zakishah has asked for the wisdom of the Perl Monks concerning the following question:
How can i save the two IPs e.g. "10.10.10.10" in two different variable which appear after the second keyword "Static". My text file looks like this
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
My code looks something like this but it does not seem to work
Thankswhile(my $line = <DATA>) { if(/\bStatic\b/){ if(/\bStatic\b/){ my $IP = $line =~ /\d+\.\d+\.\d+\.\d+/; push(@IPS, $IP); } else { } } } print @IPS;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding specific keyword in Perl
by choroba (Cardinal) on Aug 21, 2012 at 14:35 UTC | |
by zakishah (Novice) on Aug 21, 2012 at 14:55 UTC | |
|
Re: Finding specific keyword in Perl
by tobyink (Canon) on Aug 21, 2012 at 14:52 UTC | |
by BillKSmith (Monsignor) on Aug 21, 2012 at 17:09 UTC | |
|
Re: Finding specific keyword in Perl
by Kenosis (Priest) on Aug 21, 2012 at 16:17 UTC |