Next | Tricks of the Wizards | 27 |
$data = read_block(FH); # Doesn't work
package My::IO;
sub read_block { my $fh = shift; my $buf; read $fh, $buf, $BLOCKSIZE; $buf; }
Solution 1:
$data = read_block(main::FH);
Solution 2:
$data = read_block(\*FH);
Perl's I/O functions all will glob references
They then access the glob through the reference instead of through the stash
Next | Copyright © 2003 M. J. Dominus |