Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I need some help with this, I have written a code which takes in input of multiple files and then it is supposed to process each file and save its output in a seperate file for each, but what is happening is that everytime i run the program it takes the new file created as the input as well. And for example my variable $ip is in the program its defined it just shows up that uninitialised any help on this?

#!/usr/bin/perl -w use Regexp::Common qw/net/; use warnings; #use strict; use Regexp::Common qw/net/; use strict; use Cwd; my $mypath=getcwd(); my $mypath=$mypath."/sd"; my $ip; chdir $mypath; my @files = <*>; my $var=0; my $i = 0; my $traceroute; my $line; foreach (@files) { if (-f $_) { process ($_); } } sub process { my $file2 = $_[0]; open my $in, '<', $file2 or die $!; open my $out, '>', "$file2.log" or die $!; while (my $line = <$in>){ if($line =~ /^Traceroute: .* (\S+)/) { $traceroute = $1; #print "$traceroute\n"; $var++; #print "$traceroute\n"; } my ($ip) = $line =~ /(?: \d+ \s \s+) ($RE{net}{IPv4}) /msx +; print "$ip\n"; if($traceroute eq $ip){ print {$out} $ip if defined ; if($ip ne undef){ {$i++;} } } else { } } print {$out} "Number of traceroutes - $var\n"; print {$out} "Number of traceroutes reached destination - $i\n"; my $subs = $var-$i; print {$out} "Number of traceroutes that did not reaach destination ($ +subs)\n"; my $perc = ($i/$var)*100; print {$out} "Percentage of sucessful traceroutes ($perc%)\n"; # ... your remain code here }

In reply to Reading Multiple files by maheshkumar

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (6)
    As of 2014-08-23 21:35 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (178 votes), past polls