Your regex is wrong. $line is not storing the IP in that case.
$line =~ /^(\d+\.\d+.\d+\.\d+)/; #Extact the IP address
Should be /^(\d+\.\d+\.\d+\.\d+)/ #See the missing char? Forgot to escape
your second dot. OK, so that might match anyway but sloppy regex can be
quite nasty.
I did this just
While that would work, since it is only a one line text file containing a
single I.P. address a much simpler way would be:
#!/usr/bin/perl -w
open(IPFILE, ");
The regex is, in this case at least, not really necessary.
Note the the key here is the chomp() function which removes any newline
ch
Uncertain what you are attempting to do, but:
#!perl -w
while ( ) {
chomp;
if ( /^(\d+\.\d+.\d+\.\d+)/ ) { #Extact the IP address here and stote as $1
print "$1\n";
}
}
__DATA__
192.168.0.2
This should not print
199.88.22.111
^ Script ends here
Output:
192.168.0.2
199