Louis wrote:
Quote:
NOW: I put the calling function in another file. When it calls the print
function it uses &main::prtmess();, perl prints out errors: printf() Non
unopened filehandle FH1 at.....
Firstly, it's probably not a good idea to be splitting these functions
across packages. If they have such interrelated functionality, why split
them up at all? And certainly if you have to split them up, they
shouldn't both be operating on a global filehandle, nor will that
produce readable and maintainable code.
A better alternative would be to have one subroutine to open a
filehandle and read from it, and another subroutine to handle the
printing. And if you insist on operating directly on the filehandle, you
should be using a scalar to hold the filehandle--not a bareword--which
could then be passed to another function.
Quote:
My question is: I read somewhere that once you open a filehandle, perl
keeps it open until you close it. So why the different file scenario
doesn't seem to work?
Read documentation on Perl's symbol tables. Until then, stick with
scalars as filehandles.