in reply to printing and logging to a file

Thanks for the responses - the Suffering from Buffering is a great read.

I have a question regarding select - doesn't all STDOUT go to the selected file handle unless otherwise stated?

for example:


#!/usr/local/bin/perl

open (OUT, ">/tmp/out.file");

$fh = select (OUT);
$| = 1;
select($fh);

print STDOUT "Hello!\n"; # prints to stdout
print "Hello!\n";        # prints to $fh = /tmp/out.file as no filehandle has been stated

So, in the above example, we have selected a filehandle - Am I correct in believing that unless explicitly stated, all output will be directed to OUT - the selected filehandle?

Replies are listed 'Best First'.
Re: Re: printing and logging to a file
by blakem (Monsignor) on Jan 09, 2002 at 05:04 UTC
    The return value from select() is the previously selected filehandle. Therefore $fh is actually STDOUT (i.e. the filehandle that was hot before the select), so when you select($fh) you are back with STDOUT as your Currently-Selected-Filehandle. Does that make sense?

    -Blake