On 2/13/02 2:44 PM, dan radom <[EMAIL PROTECTED]> wrote:
> Hi,
>
>
> I've got a problem with the following code...
>
> my @hosts=qw( lunar solar venus mars saturn pluto );
>
> foreach (\@hosts) {
> system("/usr/bin/ssh @hosts $ARGV[0]");
> }
>
> ....
>
> What I'm wanting to do is call foo.pl uname (for example) and have the script
> ssh host uname for each host defined in the @hosts array. What's currently
> happening is that it does ssh lunar solar and dies trying to execute the next
> @hosts as the ssh commend. Any ideas?
>
> dan
Hi Dan,
foreach works on arrays, not array references. ie,
foreach $letter ('a', 'b', 'c', 'd'){
print "$letter\n";
}
You can do the same thing with an array:
@letters = ('a', 'b', 'c', 'd');
foreach $letter (@letters){
print "$letter\n";
}
The variable you give before the list ($letter, in this case) stores the
item of the list you're currently iterating over (otherwise, that value is
stored in the special variable $_. So what I believe you're trying to do is:
my @hosts=qw( lunar solar venus mars saturn pluto );
foreach my $host (@hosts) {
system("/usr/bin/ssh $host $ARGV[0]");
}
Hope that helps,
--
Michael
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]