in reply to Re: {} vs do{}
in thread {} vs do{}

Hmmmm ... what about this:

open( FH1 , '>foo' ); open( FH2 , '>bar' ); @fhs = ( FH1 , FH2 ); print { $fhs[ $_ % 2 ] } "$_\n" for ( 1 .. 10 );
which does actually put odds in one file and evens in another.

I understood this as the BLOCK returning the last value. Is something else going on?

Scott 'Confused in Indiana' Crittenden

Replies are listed 'Best First'.
Re: Re: Re: {} vs do{}
by MeowChow (Vicar) on Jul 05, 2001 at 01:44 UTC
    the print BLOCK LIST form is, I suspect, analagous to something like map BLOCK list, where the BLOCK is converted into an anonymous sub which returns the value of the last expression in the block. These are syntactically different from naked BLOCKs. You can also get this behaviour with subroutine prototypes:
    sub MySub (&\@) { ... } MySub { # do something, return a value } @list;
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
Re: Re: Re: {} vs do{}
by John M. Dlugosz (Monsignor) on Jul 21, 2001 at 01:47 UTC
    The "indirect object" uses a block for its syntax, and is a different rule than a general block in the middle of an expression.