> >   my $x = do { code };
> > works, because do flips the context, expecting a block and
> > returning a value.
> 
> I hadn't actually thought of it that way, but it's remarkably well
> explained. Well done.

Thanks!

> > That way I can say
> >   my $fh = do { local $_ };
> >   open $fh, $file or die $!;
> 
> Ah, now that's not quite right. The 'do' block will create a
> local copy of $_, initialised to 'undef'. The end of the block
> returns 'undef' as it is the last executed line, and $_ will
> be restored from its saved value. The line is therefore the
> same as:
> 
>     my $fh = undef;
> 
> or just
> 
>     my $fh;
> 
> and the entire code works as:
> 
>     open my $fh, $file or die $!;

I goofed. Should have been 

  my $fh = do { local *_ };

which can be passed to things that are expecting a filehandle, and NOT
a plain scalar.

> >   use FileHandle;
> >   my $fh = new FileHandle $file or die $!;
> 
> If we're counting lines, I think mine wins!

Agreed! Especially in this contrived context, lol....
But thanks for pointing out my goof. I do that *WAY* too much.
Lately I at least try to *run* most of the code snips before I post
them, but sometimes these contrived examples work even though there's a
lot of unnecessary gyration! >:0P

__________________________________________________
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]

Reply via email to