I thought that by being declared inside [- -], the subroutine would be
recompiled on every request, thus losing any reference to @fields.
Jonny
J>-----Original Message-----
J>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
J>Sent: Wednesday, February 28, 2001 10:37 PM
J>To: [EMAIL PROTECTED]
J>Subject: Re: problem with subroutines caching values of variables
J>
J>
J>On Wed, Feb 28, 2001 at 06:08:43PM -0000, Jonny Cavell wrote:
J>> [-
J>> my @fields = qw(a b);
J>> print OUT "@fields";
J>> sub testingit{
J>> print OUT "@fields";
J>> }
J>> -]
J>>
J>> The first print gives the correct value ("a,b")
J>> The second print gives an incorrect answer occasionally -
J>seemingly an old
J>> version of the variable.
J>
J>if i understand things correctly:
J>
J>embperl cleans up the variables used in each page by undef'ing them
J>after the page has executed.
J>
J>your sub keeps a reference to @fields, and it continues to use the
J>original @fields, even when the "real" @fields has been undef'ed and
J>recreated. this is actually a feature of perl (see "Private Variables
J>via my()" in perlsub(1p) and anything talking about "closures").
J>
J>> Interestingly, if I declare @fields in [$ var $] the
J>problem does not seem
J>> to occur.
J>
J>i'm guessing that embperl doesn't undef variables in this case (?), so
J>both the function and new users of the variable are actually accessing
J>the same thing.
J>
J>
J>so:
J>
J>you can't do anything about it, except:
J>
J>1. avoid that construct. if you have to use variables local to the
J>page, you should be using %mdat anyway.
J>
J>2. use [$var$] declarations, since they seem to work.
J>
J>--
J> - Gus
J>
J>---------------------------------------------------------------------
J>To unsubscribe, e-mail: [EMAIL PROTECTED]
J>For additional commands, e-mail: [EMAIL PROTECTED]
J>
BUY YOUR 2001 ISA AT INTERACTIVE INVESTOR'S NEW ISA CENTRE - visit
http://www.iii.co.uk/isa for a choice of 400+ funds, market leading
discounts
and access to expert advice.
FANCY A FREE ISA? Enter our competition now at http://www.iii.co.uk/isa
Terms and Conditions apply and are available online.
Issued by Interactive Investor Trading Limited, regulated by the SFA.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]