> That's no different than the current state of affairs.
> 
>    $oldoutput = *STDOUT;
>    *STDOUT = $filehandle;
> 
> I don't see how select() is any less needed under this proposal than it is now.

Perl 5 has the concept of a "currently selected filehandle". So,
whatever is selected by select() is what lots of stuff, like print() and
$|, works on.

What I was trying to get at is that we should think about ditching this
approach in favor of one that uses object methods and $STDOUT always. So
instead of:

   select(MYFILE);
   $| = 1;

We now write:

   $myfileobject->autoflush(1);

Which you can do now, but most people don't because it isn't builtin.
Instead, make this the way to do it. It's clearer and gets rid of having
to maintain the currently selected filehandle.

For other stuff, like print(), instead of using the "currently selected
filehandle", just always have it print to $STDOUT unless something's
specified. So:

   $oldstdout = $STDOUT;
   $STDOUT = $myfileobject;
   print "Hello, world!";   # always prints to $STDOUT, which in
                            # this case is a copy of $myfileobject

   $STDOUT = $oldstdout;
   print "Hello, world again!";

The rule is easier ("print always goes to $STDOUT, whatever that
contains") and there's not select() overhead. Everything else should be
object methods, making stuff clearer still.

In any case, that's the idea. I'm not necessarily heartset on it, but I
do think it makes things simpler and faster. The "currently selected
filehandle" is something every beginner I've talked to has a ton of
trouble comprehending. They tend to have the folk theory of "everything
goes to STDOUT by default". If we make that "everything goes to $STDOUT
by default" this can be the actual way it works.

-Nate

Reply via email to