in reply to auto-vivifying file handles
But lexically scoped filehandles have something to say for them. And you can even do it in Perl 5.005. Consider:
There you are. Now you can just write:use Carp; # time passes # Takes a name to open, returns an open filehandle sub my_open { my $file = shift; # Put the declaration in the open to confuse people? :-) my $fh = do {local *FH}; open($fh, $file) or confess("Cannot open '$file': $!"); return $fh; }
and you will have lexically scoped filehandles. The only gotcha is that people may get confused about why they cannot use them like this:my $handle = my_open("whatever");
but instead must either put the handle in a scalar, turn print into a method call, or use the syntactic trick:print $self->{handle} @stuff;
print { $self->{handle} } @stuff;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re (tilly) 1: auto-vivifying file handles
by blakem (Monsignor) on Sep 26, 2001 at 03:46 UTC | |
by tilly (Archbishop) on Sep 26, 2001 at 05:47 UTC | |
|
Re: Re (tilly) 1: auto-vivifying file handles
by John M. Dlugosz (Monsignor) on Sep 25, 2001 at 23:20 UTC | |
by tilly (Archbishop) on Sep 26, 2001 at 01:00 UTC | |
by John M. Dlugosz (Monsignor) on Sep 26, 2001 at 02:26 UTC |