Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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

by Rudolf (Pilgrim)
on Aug 27, 2012 at 22:28 UTC ( #990075=note: print w/replies, xml ) Need Help??

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

for looping through the array, you dont really need the index unless your doing something special with the data, I am assuming what you want to do but for your loop at the end here is what I suggest:

close FILE;#dont forget to close your file for(my $i=0;$i<scalar(@dude);$i++){ system("ssh a.AS1 tracerout $dude[$i] > file $i.txt"); }

not sure why you used the + sign, maybe your looking for the . that connects strings ? and your use of $0 is also confusing because it is the path to the perl script itself.. this could not be used as an index. possibly you ment to say $dude[$o] which would make a lot more sense. but your problem is that the correct way to index an array is by putting it into scalar context ( $dude[$i] ) because the bit of information your taking from the array is flat data you begin it with a dollar sign instead of the @.

FIXED: length(@dude) to scalar(@dude) thanks jethro

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990075]
[choroba]: So, I joined Pod Černư Vrch some months ago to still have the fun. But I wouldn't call it "punk" anymore...
[LanX]: choroba deaf after one rehearsal per year ?
Discipulus .. per ear!
[LanX]: LOL
[choroba]: we used to play more :)
Discipulus played the guitar in a ska band 12 elemnts, very fun
[LanX]: well ... the prize for worshipping satan is high ...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2017-03-24 12:35 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (301 votes). Check out past polls.