
rovf
Veteran
Feb 28, 2013, 3:12 AM
Post #2 of 3
(123 views)
|
|
Re: [struct] help a newbie: how to read external hostfile list and execute a scp command to copy to listed hosts??
[In reply to]
|
Can't Post
|
|
First, I would remove the trailing \n from the lines you read, before storing them into @lines: An even better alternative would be to just transfer all the lines at once and omitting the push:
open(my $fh,'<',$file) # This is the preferable way to use 'open' or die "...."; my @lines = map {chomp;$_} (<$fh>); close $fh; Of course the question is, *why* you need the content of the file stored in an array. Do you need it repeatedly? If you only need it for the scp, the array is unnecessary. For running scp, you have two choices: my $exitcode_and_errorcode=system("scp ...."); my $output=qx(scp ... 2>&1); In the latter case, you get the output stored in a file. In the former one, the output goes to stdout/stderr.
|