Harry Putnam wrote:
I happen to be scripting something that needs to have two logs written to and was sort of taken by how awkward this construction looked: (Simplified for discussion, from a longer script) my $rsync = 'rsync'; my $tmplog = 'one.log'; my $tmplog2 = 'two.log'; open(LOG,">>$tmplog")or die "Can't open $tmplog : $!"; open(LOG2,">>$tmplog2")or die "Can't open $tmplog2: $!"; print LOG "kdkdkdkd Output from:\n$rsync cmdflgs"; print LOG2 "kdkdkdkd Output from:\n$rsync cmdflgs" close(LOG); close(LOG2); Is there some smooth way to write to more than one log?
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"; } 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/