in reply to Passing a Filehandle that Might be a Bareword
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...)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Passing a Filehandle that Might be a Bareword (\*)
by tye (Sage) on May 30, 2010 at 17:23 UTC | |
|
Re^2: Passing a Filehandle that Might be a Bareword
by Xiong (Hermit) on May 30, 2010 at 16:19 UTC | |
|
Re^2: Passing a Filehandle that Might be a Bareword
by Xiong (Hermit) on May 30, 2010 at 16:38 UTC |