I will be thankful for any help.
Well, am not sure whether the following will be any help, but...
Looks like you're gathering and displaying IPs from a set of files, then printing 'Routing Loop Detected' at the end if an IP's been duplicated in that set.
An alternative to manually opening files is to use File::Slurp qw/read_file/;, as it returns a file's lines in a list context. Give this, and the excellent feedback already provided, consider the following option:
use Modern::Perl; use File::Slurp qw/read_file/; use Regexp::Common qw/net/; sub R_loop2 { my ( $file, $loop, %seen ) = 'junk.txt'; for my $fileName ( read_file $file ) { chomp $fileName; say 'The packet traversed this path:'; for my $fileLine ( read_file $fileName ) { $fileLine =~ /($RE{net}{IPv4})/ or next; $loop++ if ++$seen{$1} > 1; say $1; } } if ($loop) { say 'Routing Loop Detected'; return 1; } }
Each line in the files whose names are contained in junk.txt is processed using Regexp::Common qw/net/ to match/capture IP addresses. Duplicate IPs are tracked, just before printing the IP address, by incrementing $loop, and 'Routing Loop Detected' will print at the end if $loop is set.
Hope this helps!
In reply to Re: No such file or directory at R_loop2.pl line 19.
by Kenosis
in thread No such file or directory at R_loop2.pl line 19.
by zakishah
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |