Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Split() first 3 elements of @array

by ig (Vicar)
on Aug 28, 2012 at 20:40 UTC ( #990331=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Split() first 3 elements of @array
in thread Split() first 3 elements of @array

I cannot sxtract the IP address for the switch for some reason

The third line, with the IP address is indented: there is some whitespace at the beginning of the line, but your regular expression is looking for 'IP' at the beginning of the line: /^IP/. Change that to accept some leading whitespace and you should get a match: /^\s*IP/


Comment on Re^3: Split() first 3 elements of @array
Select or Download Code
Re^4: Split() first 3 elements of @array
by Kenosis (Priest) on Aug 28, 2012 at 20:48 UTC
    use Modern::Perl; use Modern::Perl; say ' IP address: 10.10.10.10' =~ /IP\s+address:\s+([^\s]+)/; say 'IP address: 10.10.10.10' =~ /IP\s+address:\s+([^\s]+)/; say ' IP address: 10.10.10.10' =~ /^\s*IP\s+address:\s+([^\s]+)/; say 'IP address: 10.10.10.10' =~ /^\s*IP\s+address:\s+([^\s]+)/;

    Output:

    10.10.10.10 10.10.10.10 10.10.10.10 10.10.10.10

    Update: Ah! hmb104 was referring to using split, not the regex (which isn't attempting to match at the beginning of a line and is fully anchored w/o mentioning the spaces before "IP address:").

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990331]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2015-07-07 05:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls