Use of uninitialized value $destination_IP in string ne at...
####
ns1.sina.com.cn. 80800 IN A 202.106.184.166
####
clear in_list flag
FOR each line in the data file
IF line matches first line of a list THEN
extract IP
save IP as source
set in_list flag
ELSE
IF in_list flag set THEN
SWITCH line
CASE line matches second list line
ignore it
CASE line matches list-address
save addresses, indexed to current source
CASE default (i.e. no longer in list)
clear in_list flag
ENDSWITCH
ENDIF
ENDELSE
ENDFOR
####
#! perl
use strict;
use warnings;
my $line1_re = qr! ^ Traceroute: \s+ .* \s+ (\S+) $ !x;
my $line2_re = qr! ^ traceroute !x;
my $destn_re = qr! ^ # start of line
\s* # optional whitespace
\d+ # sequence number: nnn
\s+ # whitespace
(?: # EITHER
(?: \d{1,3} \. ){3} \d{1,3} # IP address: nnn.nnn.nnn.nnn
| # OR
\* \s+ \* \s+ \* # * * *
)
!x;
my (%ipToRoute, $source_IP, $in_tracing);
while (my $line = )
{
chomp $line;
if ($line =~ /$line1_re/)
{
$source_IP = $1;
$in_tracing = 1;
}
elsif ($in_tracing && $line !~ /$line2_re/)
{
if ($line =~ /$destn_re/)
{
$line =~ s/ ^ \s+ //x;
my $destination_IP = (split /\s+/, $line)[1];
push @{ $ipToRoute{$source_IP} }, $destination_IP
unless $destination_IP eq '*';
}
else
{
$in_tracing = 0;
}
}
}
foreach (keys %ipToRoute)
{
my $final_destination = @{ $ipToRoute{$_} }[-1];
printf "Destination to %s but reached %s\n",
$_, $final_destination unless $_ eq $final_destination;
}
__DATA__
Traceroute: 22 1291136399 1291136393 1291136393 LocalDNS home.china.com.cn 221.204.248.107
traceroute to 221.204.248.107 (221.204.248.107), 30 hops max, 60 byte packets
1 134.2.173.254 0.170 ms 0.191 ms 0.185 ms
etc.
####
Destination to 92.123.72.112 but reached 92.123.72.0
Destination to 78.108.81.20 but reached 217.106.1.146
Destination to 208.78.244.38 but reached 208.78.244.0