--- Rob Dixon <[EMAIL PROTECTED]> wrote: > Paul wrote: > > > do { > > > my $empty; > > > $empty ++; > > > }; > > > > Also, the do() is superfluous here, isn't it? > > I was trying to show something that would return a value in > the same way as a subroutine block (so that I didn't need a > return statement in the same way as a subroutine doesn't). > I started out with a bare block, but realised that it needed > a 'do' to have a value, and therefore make it non-redundant > in context.
Got it. my $x = { code, more code.... } doesn't work, because the braces are expecting to be an anonymous hash in that context, so they aren't a block. my $x = do { code }; works, because do flips the context, expecting a block and returning a value. That way I can say my $fh = do { local $_ }; open $fh, $file or die $!; for a cheap, quick, anonymous filehandle in a scalar. :) (note to the peanut gallery: henceforward I digress!) I've definitely used that trick...but all in all, for that *particular* usage I recommend use FileHandle; my $fh = new FileHandle $file or die $!; which is much more readable to the uninitiated, and still only two lines of code. ;o] __________________________________________________ Do you Yahoo!? Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]