Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Finding specific keyword in Perl

by Kenosis (Priest)
on Aug 21, 2012 at 16:17 UTC ( [id://988788]=note: print w/replies, xml ) Need Help??


in reply to Finding specific keyword in Perl

Another option is to regex your file's slurped contents:

use Modern::Perl; my $fileContents = <<END; 0.0.0.0/0 *[Static/5] 02:30:27 > to 192.168.4.126 via em0.0 10.0.0.36/30 *[OSPF/10] 01:46:15, metric 2 > to 10.0.0.106 via em1.0 [BGP/170] 01:43:15, localpref 100, from 10.0.0.131 AS path: I 10.0.0.128/32 *[Static/5] 02:22:14 > to 10.0.0.110 via em2.0 [OSPF/10] 01:46:15, metric 3 > to 10.0.0.106 via em1.0 END { local $/; open my $fh, '<', \$fileContents or die $!; my $data = <$fh>; my @IPs = $data =~ /Static.+Static.+> to ([\d.]+) via.+> to ([\d.] ++) via/s; say for @IPs; }

Output:

10.0.0.110 10.0.0.106

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-19 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found