On 5/1/07, brian d foy <[EMAIL PROTECTED]> wrote:
I was thinking about default filehandles yesterday. select() doesn't
seem to be around except as an "Unfiled" function in S16.

Then, as I was looking at

   .say( "Hello World" );

At various times, I have seen something to the effect of each of the
following being bandied about:

 $*OUT.say( "Hello World" );
 "Hello World".say;

That is, both filehandles and strings have 'say' methods that do
essentially the same thing, but using subtly different syntax.  How
would I use &("Hello World".say) to write to filehandle $FH?  My gut
reaction would be to use an adverb for the purpose:

 "Hello World".say :to($FH);

This would also work for the sub version:

 say :to($FH) "Hello World";

With this in mind, you probably could create a localized alias for
'say', if you wanted to:

 {
   my &say := &OUTER::say.assuming(:to($FH));
   say "Hello World"; # same as 'say "Hello World" :to($FH);'
 }

The catch with this is that you'd have to do this for each output
routine separately.

How about this: Do the output routines default to the global
filehandles directly, or do they default to lexical bindings of them?
That is, does 'say' output to $*OUT in the absence of an explicit
filehandle, or does it output to $OUT (with the latter normally being
bound to $*OUT)?  If the latter, you should be able to redirect all of
your output in the rest of the current scope by saying:

 $OUT := $*ERR;

I can understand not being able to rebind the global filehandles.
After all: once they're rebound, how would you ever find what they
were originally bound to?

--
Jonathan "Dataweaver" Lang

Reply via email to