LPM: silliness
Graydon Dodson
grdodson at lexmark.com
Mon Nov 15 18:51:12 CST 1999
There is some black magic that you can do in perl to obtain a reference to
a typeglob. This reference can now be treated as a filehandle stored in a
variable including passing to subroutines etc. The really cool thing is since
it is anonymous it will not clash with any globals and automatically goes out
of scope when you are done.
{
## Annon glob
my $fh = do {local *FH }; # <---- Black magic here.
## Open and read
open ($fh, "$File")
|| die("\nERROR: unable to read \"$File\" at \""
. (caller)[1] ."\" line ". (caller)[2] ."\n");
my @lines = <$fh>;
## Close and exit
close($fh);
}
Learned this one from the Perl Journal.
Graydon Dodson (606) 232-6483 grdodson at lexmark.com
Lexmark International Inc.
More information about the Lexington-pm
mailing list