http://www.perlmonks.org?node_id=398146

warpod has asked for the wisdom of the Perl Monks concerning the following question:

What is wrong with this code?
==== test. pl ====== #!/usr/bin/perl use strict; use mmm; local* F; mmm::fopen(F, ">tst"); print F "hi"; mmm::fclose F; ==== mmm.pm ====== #!/usr/bin/perl use strict; package mmm; BEGIN {} sub fopen(*;$) { local *FH = $_[0]; return CORE::open(FH, $_[1]); } sub fclose(*) { local *FH = $_[0]; return CORE::close(FH); } END { } 1;
when executed it says:
print() on unopened filehandle F at test.pl line 7.
but if I move fopen and fclose into test.pl, then this code
local* F; fopen(F, ">tst"); print F "hi"; fclose F;
works just fine. What is wrong in package?