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 in front of keyword "static" second appearance and till the end of file.means where ever it find keyword "static" in the file it only prints ip addresses in front of those lines except first appearance of 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 10.0.0.134/32 *[Static/5] 00:00:27 > to 10.0.0.110 via em2.0 [OSPF/10] 07:33:09, metric 5 > to 10.0.0.106 via em1.0 [BGP/170] 07:39:33, localpref 100, from
My code looks something like this but it does not seem to work
open FILE, '<', "table.txt" or die $!; my $static = 0; my @IPS; while (<FILE>){ push @IPS, $1 if /([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) + +/ and $static > 1; $static++ if /Static/; } print @IPS;
|
|---|