in reply to Re: Passing filehandles to subroutines
in thread Passing filehandles to subroutines

I'd prefer to keep an explicit filehandle on my prints and default it as in $fh ||= \*STDOUT or something like that. I still get all of the functionality you mention and without having to mess with a global variable (ie the "selected filehandle").

Makeshifts last the longest.

  • Comment on Re^2: Passing filehandles to subroutines

Replies are listed 'Best First'.
Re: Re^2: Passing filehandles to subroutines
by rdfield (Priest) on Feb 17, 2003 at 11:37 UTC
    I knew I'd come up with a concrete counter-example eventually :)

    I use Pod::HTML in a mod_perl handler to generate "Help" screens on the fly when a user clicks on the Help menu item in my CGI application. The module uses a named filehandle, which when used in "interactive" mode is opened against "". Works great from the command line - but completely baulks under mod_perl. Back to the drawing board: I worked around it by supplying it with a temporary (session based) file name, and then reading the resultant file and printing it to (what appears to be) STDOUT.

    rdfield

      I don't see why the same approach wouldn't be applicable in that case if you do it right. Have you tried something like the following?
      open PODHTMLFH, ">&=STDOUT" or die "Can't dup STDOUT\n"; # or even more generically open PODHTMLFH, ">&=".fileno(STDOUT) or die "Can't dup STDOUT\n";
      Temporary files are icky.

      Makeshifts last the longest.

        Eh? How does my program dup'ing STDOUT force Pod::HTML's open HTML,">-"; to print to mod_perl's tied default filehandle?

        (and yes, temporary files are very icky indeed)

        rdfield