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?

I tried just adding the second one to the first print like this:

 print LOG LOG2 "[...]";

  But that fails with an error:

  String found where operator expected at ./t1.pl line 109, near "LOG2
  "kdkdkdkd Output from:\n$rsync cmdflgs""

        (Do you need to predeclare LOG2?)

  syntax error at ./t1.pl line 109, near "LOG2 "kdkdkdkd Output
  from:\n$rsync cmdflgs""

  Execution of ./t1.pl aborted due to compilation errors.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to