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!!


In reply to Passing file handle to tee that goes into open by pjkang7

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.