Rob Dixon wrote:
On 27/08/2013 23:06, John W. Krahn wrote:
my %logs = (
'one.log' => undef,
'two.log' => undef,
);
for my $name ( keys %logs ) {
open my $FH, '>>', $name or die "Cannot open '$name' because: $!";
$logs{ $name } = $FH;
}
for my $log_FH ( values %logs ) {
print $log_FH "kdkdkdkd Output from:\n$rsync cmdflgs";
}
Nice John
It compacts neatly to
use strict;
use warnings;
use autodie;
my $rsync = 'rsync';
my $tmplog = 'one.log';
my $tmplog2 = 'two.log';
my %logs = map {
open my $FH, '>>', $_;
What if open fails?!
($_ => $FH);
} $tmplog, $tmplog2;
Or a bit more compact:
my %logs = map {
open my $FH, '>>', $_ or die "Cannot open '$name' because: $!";
( $_ => $FH );
} my ( $tmplog, $tmplog2 ) = qw( one.log two.log );
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/