[Canberra-pm] Recursion in Perl

Jepri jepri at alphacomplex.org
Wed May 24 19:09:19 PDT 2006


Heh, I had to resubscribe to the list to post this

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, possibly causing 
the first one to close.  I'm a bit vague here because I never use 
FILEHANDLES due to their scoping issues.

If you use the (much better) lexical

my $handle; open $handle, "<", "file"

then $handle is lexically scoped and will be handled with the usual 
variable rules.  If you're using this method  then I'd really need to 
see some code to help further.

HTH,
Jeremy

Andrew Pollock wrote:

>My turn to ask a question.
>
>(Disclaimer: recursion does my head in at the best of times)
>
>I'm trying to walk through a bunch a config files to build up a data
>structure that represents the inclusion relationships between them.
>
>So at the moment, as I prototype this, I've got a subroutine that will call
>itself again on a file if it hasn't already seen it, and see what includes
>it mentions, and then call itself again on them.
>
>What I seem to be encountering is a bunch of "readline() on closed
>filehandle" errors, so I'm wondering if the filehandle namespace isn't
>unique to each call of the subroutine, and I'm closing it in a subsequent
>invokation, or I've caused my brain to explode in another more subtle
>manner.
>
>regards
>
>Andrew
>_______________________________________________
>Canberra-pm mailing list
>Canberra-pm at pm.org
>http://mail.pm.org/mailman/listinfo/canberra-pm
>
>  
>



More information about the Canberra-pm mailing list