in reply to Recursive file opening: reading an undef at the end of file

Not trying to answer your question, but where is your close? Once you are done with an opened file, just close it. Regardless what Perl might do for you towards those open files, it is a bad style not to close the files you opened. People might use those little things to judge whether you are professional.

  • Comment on Re: Recursive file opening: reading an undef at the end of file

Replies are listed 'Best First'.
Re: Re: Recursive file opening: reading an undef at the end of file
by ysth (Canon) on Dec 24, 2003 at 04:17 UTC
    Because a lexical filehandle was used, the file opened by each call to the subroutine will be closed when the that call to the subroutine returns.

    There may be a problem if you are expecting hundreds of nested calls, but otherwise there is nothing wrong here. Each file is closed immediately after reaching its end.

Re: Re: Recursive file opening: reading an undef at the end of file
by thor (Priest) on Dec 24, 2003 at 02:34 UTC
    it is a bad style not to close the files you opened
    A few things:
    1. This was a quick and dirty script. Wrote it in about 5 minutes. Were this a production level script, I'd have done things differently.
    2. As I was using scalars ($fh) instead of barewords (FH), and I was lexically scoping them with 'my', the files are closed when the scalar goes out of scope. I tend to use features of the language when available.

    thor

      Point taken, it was quick and dirty. All the same, I consider it a good idea to have the habit of writing the close when you write the open. But then, too, I'm one of the those people that fastens the safety belt by habit, even if I'm going two blocks. So have a grain of salt with this post.