CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Get part of the string

 



sh.ajay12
User

May 14, 2014, 8:12 AM

Post #1 of 4 (2411 views)
Get part of the string Can't Post

Dear Members,

How can i get part of the string.

I want to get only
DCREST.CHADWELL-HEATH.1of1

from this string

/usr/local/nagios/DCREST/etc/pnp4nagios/pages/DCREST.CHADWELL-HEATH.1of1.cfg

Thank you Everyone from Ajay


FishMonger
Veteran / Moderator

May 14, 2014, 8:19 AM

Post #2 of 4 (2410 views)
Re: [sh.ajay12] Get part of the string [In reply to] Can't Post

You can use a regex, the split function, or the File::Basename module.
http://search.cpan.org/~rjbs/perl-5.18.2/lib/File/Basename.pm

What have you tried?
What errors/warnings are you receiving?


sh.ajay12
User

May 14, 2014, 8:28 AM

Post #3 of 4 (2408 views)
Re: [FishMonger] Get part of the string [In reply to] Can't Post

Hello Members,

I have tried this one and its working

$link=/usr/local/nagios/DCREST/etc/pnp4nagios/pages/DCREST.CHADWELL-HEATH.1of1.cfg

(our $wanted)= $link =~ /pages\/(.*)\.cfg/g;

Thank you FishMonger


FishMonger
Veteran / Moderator

May 14, 2014, 8:33 AM

Post #4 of 4 (2404 views)
Re: [sh.ajay12] Get part of the string [In reply to] Can't Post

Why are you declaring $wanted as a global? 99.99% of the time that is the wrong thing to do. You should declare it as a lexical var.


Code
my ($wanted) = $link =~ /pages\/(.*)\.cfg/;



(This post was edited by FishMonger on May 14, 2014, 8:34 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives