[Canberra-pm] Recursion in Perl
Andrew Pollock
andrew-pm at andrew.net.au
Wed May 24 19:13:57 PDT 2006
On Thu, May 25, 2006 at 12:02:03PM +1000, Jepri wrote:
> You haven't included any code, so I'm going to have to guess a little here.
>
> If you are using filehandles created with
>
> open HANDLE, "<file"
>
> then HANDLE is NOT lexical (does not behave like a normal variable), and
> further calls to your function will overwrite HANDLE, probably causing
> the first one to close. I'm guessing here because I never use
> FILEHANDLES due to their scoping issues.
I was using this method.
> If you use the (much better) lexical
>
> my $handle; open $handle, "<file"
>
> then $handle is lexically scoped and will be automatically closed when
> you leave scope. If you're using this construction then I'd really need
> to see some code to help further.
Yeah, this looks (and sounds) better. I actually got around the problem
(mostly) by loading up an array with all the files I discovered, and then
after I closed the file, loop over the array and call the recursive
subroutine, so the file wasn't kept open as it recursed.
regards
Andrew
More information about the Canberra-pm
mailing list