Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: how to save result in multiple files using for loop in perl

by jethro (Monsignor)
on Aug 27, 2012 at 22:33 UTC ( #990077=note: print w/replies, xml ) Need Help??

in reply to how to save result in multiple files using for loop in perl

Never ever use a variable named $o (dollar-ow) !!!! As you can see (or not see), you seem to be using $0 (dollar-zero) in your system call instead

You probably will find a file named file<your scriptname>.txt in your directory, because the name of your script is usually stored in $0 (dollar-zero).

There is another bug in your script: Since you initialize $num with @dude+1, your for loop will always try to access an undefined value after the end of your array. You might like to use the following instead, much less error-prone

my $i=0; for my $ip (@dude) { system ("ssh a.AS1 traceroute $ip > file${i}.txt "); $i++; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990077]
shmem .oO( someday I'll do something... and then I'll make it big. Now is the time! )
[LanX]: don't forget to flush the water
[shmem]: the day will come when LanX hits the fan
[Discipulus]: did you remember to commit?
[Discipulus]: if you hit the fan the cpu can overheat..

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2018-04-24 11:31 GMT
Find Nodes?
    Voting Booth?