package My::Module; shift; # throw away my own package name our $fh = shift; {...} # check to see it's a good filehandle sub later { print $fh, 'Arbitrary text.'; }; 1;
I think you rather meant:
package My::Module; our $fh; sub import { shift; # throw away my own package name $fh = shift; #{...} # check to see it's a good filehandle } sub later { print $fh 'Arbitrary text.'; } 1;
As for what arguments to allow, I would not go to the trouble of allowing bareword filehandles (STDOUT) or filehandle names as strings ('STDOUT'), but a file name passed as a plain string (use My::Module '/var/foo.log';) might make sense, IMHO, in which case the module would open the corresponding handle. (You could use ref \$fh in the module's import routine to tell apart...)
In reply to Re: Passing a Filehandle that Might be a Bareword
by almut
in thread Passing a Filehandle that Might be a Bareword
by Xiong
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |