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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |