[Canberra-pm] Recursion in Perl
Kim Holburn
kim at holburn.net
Wed May 24 20:16:33 PDT 2006
There's an excellent section on why not to use bare-word filehandles
in "Perl Best Practises" which explains it but I always forget it and
do it wrong.
On 2006 May 25, at 12:13 PM, Andrew Pollock wrote:
> 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
> _______________________________________________
> Canberra-pm mailing list
> Canberra-pm at pm.org
> http://mail.pm.org/mailman/listinfo/canberra-pm
>
--
Kim Holburn
Network Consultant
Ph: +61 2 61258620 M: +61 417820641 F: +61 2 6230 6121
mailto:kim at holburn.net aim://kimholburn
skype://kholburn - PGP Public Key on request
Cacert Root Cert: http://www.cacert.org/cacert.crt
Aust. Spam Act: To stop receiving mail from me: reply and let me know.
Use ISO 8601 dates [YYYY-MM-DD] http://www.saqqara.demon.co.uk/
datefmt.htm
Democracy imposed from without is the severest form of tyranny.
-- Lloyd Biggle, Jr. Analog, Apr 1961
More information about the Canberra-pm
mailing list