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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.