in reply to using lexically scoped variable as a filehandle

That's perfectly fine, as long as you don't use write, which requires filehandles (and formats) to be global, i.e they must be in the symbol table.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
  • Comment on Re: using lexically scoped variable as a filehandle

Replies are listed 'Best First'.
Re^2: using lexically scoped variable as a filehandle
by varian (Chaplain) on Feb 21, 2007 at 14:22 UTC
    Thanks all for the reassuring responses although I'm intrigued by the limitations on using non-global handles with the write function.
    Since this type of code will go into a modperl environment (so the 'program' will never really terminate) it is important to be 100% sure the system will indeed close a file and free the associated resources.
Re^2: using lexically scoped variable as a filehandle
by chromatic (Archbishop) on Feb 21, 2007 at 19:03 UTC

    They do have to be in the symbol table, but they don't have to be globals. I won't say more, however, because it's probably better to encourage novices to use something like Perl6::Form instead.