Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: No such file or directory at R_loop2.pl line 19.

by Kenosis (Priest)
on Aug 28, 2012 at 07:17 UTC ( [id://990164]=note: print w/replies, xml ) Need Help??


in reply to No such file or directory at R_loop2.pl line 19.

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!

Replies are listed 'Best First'.
Re^2: No such file or directory at R_loop2.pl line 19.
by zakishah (Novice) on Aug 28, 2012 at 09:07 UTC

    Thank you very much you really understood my problem and i really want to perform the task you just said. But problem is that i am working on platform where i have no access to download Modern::Perl module so i want to ask if there is any other way to perform this job. Thanks for your help

        you may be right , but even i changed the say to print but there are compilation error at line 1 indicating Modern::Perl . i will be so thankful if you guide me in any alternative way. THANKS

          A reply falls below the community's threshold of quality. You may see it by logging in.
      A reply falls below the community's threshold of quality. You may see it by logging in.

      I notice you've been advised (multiple times) to just remove the offending line. I suspect, though, that you may get similar messages with the other two modules.

      When there's a task like yours, it's good to first see if there's a module for it (or some components of it), as modules can help avoid 'reinventing the wheel,' are often mature and well-tested, and can reduce development time and programmatic errors. Some, however, may have to work with the Perl environment as is, with no option to install modules.

      Given the above, see the modified script below (that's not a subroutine):

      use strict; use warnings; my ( $file, $loop, %seen ) = 'junk.txt'; open my $fh1, '<', $file or die "Unable to open $file: $!"; while ( my $fileName = <$fh1> ) { chomp $fileName; print "The packet traversed this path in $fileName:\n"; open my $fh2, '<', $fileName or die "Unable to open $fileName: $!" +; while ( my $fileLine = <$fh2> ) { $fileLine =~ /(\d+\.\d+\.\d+\.\d+)/ or next; $loop++ if ++$seen{$1} > 1; print "$1\n"; } close $fh2; print "\n"; } close $fh1; print "** Routing Loop Detected **\n" if $loop;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://990164]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-16 07:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found