mabman has asked for the wisdom of the Perl Monks concerning the following question:

OK, so I've got an extremely basic question that I can't seem to find an answer to: How do I release my standard output once I've done a "select FILEHANDLE" and, once done with it, a "close FILEHANDLE"?

For instance, part of my script opens a text file for output, and then does a "select OUTPUT".

However, after I'm done writing to that file, I want to print some things back to my display, and no longer to the OUTPUT file.

But, even after I do "close OUTPUT", any "print" statement after that causes an error to display about not being able to write to the closed filehandle OUTPUT.

My environment is Win32 with the latest ActiveState release if that changes anything.

I'm sure it's something simple, I'm still a bit of a Perl newbie :)

Thanks,
Glenn

Replies are listed 'Best First'.
Re: extremely basic select() question
by Limbic~Region (Chancellor) on Oct 03, 2003 at 22:27 UTC
    mabman,
    Unless I am missing something, you can just re-select STDOUT.
    close OUTPUT; select STDOUT;

    Cheers - L~R

      Ah, I see. I was thinking it something more complicated.

      Thanks!

      Glenn

Re: extremely basic select() question
by sgifford (Prior) on Oct 04, 2003 at 04:37 UTC
    The more general way to do it, if it's possible your code will be re-used from another program that may have selected a different filehandle, is to save the return value from select, then re-select it when you're done:
    #!/usr/bin/perl -w use strict; print "To stdout\n"; my $savesel = select(STDERR); print "To stderr\n"; select($savesel); print "To stdout\n";
Re: extremely basic select() question
by bart (Canon) on Oct 04, 2003 at 09:47 UTC
    Perhaps don't select OUTPUT? You can just print directly to a filehandle using
    print OUTPUT $text, $you, $want, $printed;
    Note: no comma after the filehandle! That's how perl recognizes it as a handle.