LPM: silliness
Frank Price
fprice at mis.net
Sun Nov 14 00:40:42 CST 1999
On Sat, 13 Nov 1999, Matt Cashner wrote:
# also, if i'm reading things right, filehandles are local, correct? if so,
# what's the proper syntax to pass a filehandle to subroutines? or i
# smoking the wacky weed again? :)
Well, I don't think you can just pass them like other variables. You
can assign to a typeglob though. Since F is aliased to the typeglob
inside the subroutine block, the value of the A (and B) gets restored
once the block ends. There's probably another way to do this; I don't
use it very often.
sub prt {
local *F = shift;
my ($line) = @_;
print F "$line\n";
}
open (A, ">foo") or die "Can't open foo: $!\n";
prt(*A, 'Printing to foo ...');
close A;
open(B, ">bar") or die "Can't open bar: $!\n";
prt(*B, 'printing to bar ...');
close B;
-Frank.
____ ____
Frank Price Unix systems, Perl
fprice at mis.net & Web Programming
More information about the Lexington-pm
mailing list