Noah wrote:
Okay,
Hello,
I need a bit of help here.
OK, I'll try.
there are thousands of lines in some files.
True.
I am trying to match the lines that have
"address\s<ip_address>/<netmask>" and save the IP to $loopback except if
"lines" implies that the pattern can be found in more than one line?
the IP address/netmask is "127.0.0.1/32".
--- code snipet ----
my $ipaddressNetmask =
qr/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]+/;
grep (/address\s($ipaddressNetmask)$/, @lines) and $loopback = $1;
That's not going to work:
$ perl -le'grep /(.)/, qw/abc def ghi/ and $x = $1; print "\$x = ",
defined $x ? $x : "undef"'
$x = undef
Clues please?
my $octet = qr{25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2}};
my $CIDR_block = qr{$octet\.$octet\.$octet\.$octet/\d+};
for my $line ( @lines ) {
next if $line !~ /address\s+($CIDR_block)$/
or $1 eq '127.0.0.1/32';
my $loopback = $1;
# do something with $loopback
}
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/