pjkang7 has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I'm trying to print to multiple file handles and I have found several examples
However, when I tried to pass file handle to it, instead of file name, it fails to print. Here's several code that I tried which produces error
my $f1 = "fileName1"; my $f2 = "fileName2"; open my $fh_email, ">", $f2; #Print stuff to $fh_email open($fh, "| tee -a $f1 $fh_email") or die "Teeing off: $!\n"; #Several other variations I have tried #open($fh, "| tee -a $f1 \*$fh_email") or die "Teeing off: $!\n"; #open($fh, "| tee -a $f1 \\*$fh_email") or die "Teeing off: $!\n"; #open($fh, "| tee -a $f1 \\*\$fh_email") or die "Teeing off: $!\n"; #open($fh, "| tee -a $f1 \*\$fh_email") or die "Teeing off: $!\n"; #Wh +ich was a big mistake as I appended bunch of stuff into lots of file +(which of course I simply did svn revert *) #Print stuff into both files close $fh; #Then continue printing to $fh_email
Error message I see are something like this:
sh: -c: line 0: syntax error near unexpected token `(' sh: -c: line 0: `tee -a fileName1 \*GLOB(0x2c06b18)'
Maybe I just have to use for loop to print to both file handles.... Easy way out, but I still would like to know where I've got it wrong :(
Thanks for help!!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing file handle to tee that goes into open
by choroba (Cardinal) on Nov 09, 2016 at 22:30 UTC | |
by pjkang7 (Novice) on Nov 09, 2016 at 22:43 UTC | |
by johngg (Canon) on Nov 10, 2016 at 11:11 UTC | |
by stevieb (Canon) on Nov 09, 2016 at 23:11 UTC |