in reply to Writing to Screen and file on Win32

In a pinch, you can do it this way...

sub myprint { print @_; # Send to standard output. print FILE @_; # Also send to another filehandle. }

This approach has limitations, of course.


$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/

Replies are listed 'Best First'.
Re^2: Writing to Screen and file on Win32
by Aristotle (Chancellor) on Oct 02, 2003 at 20:07 UTC
    This approach has limitations, of course.
    Like?

    Makeshifts last the longest.

      It only handles print not printf, though that's easily fixed.

      It requires the program to be modified to call myprint() and myprintf() instead of the system versions.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
      If I understand your problem, I can solve it! Of course, the same can be said for you.

        These are inconveniences, not limitations. They don't restrict what you can do this way.

        Makeshifts last the longest.

      For example, you shouldn't pass this routine any tied variables or blessed references that will have unwanted side-effects if stringified twice instead of once.


      $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/