On Wed, Feb 28, 2001 at 06:08:43PM -0000, Jonny Cavell wrote:
> [-
> my @fields = qw(a b);
> print OUT "@fields";
> sub testingit{
>       print OUT "@fields";
> }
> -]
> 
> The first print gives the correct value ("a,b")
> The second print gives an incorrect answer occasionally - seemingly an old
> version of the variable.

if i understand things correctly:

embperl cleans up the variables used in each page by undef'ing them
after the page has executed.

your sub keeps a reference to @fields, and it continues to use the
original @fields, even when the "real" @fields has been undef'ed and
recreated. this is actually a feature of perl (see "Private Variables
via my()" in perlsub(1p) and anything talking about "closures").

> Interestingly, if I declare @fields in [$ var $] the problem does not seem
> to occur.

i'm guessing that embperl doesn't undef variables in this case (?), so
both the function and new users of the variable are actually accessing
the same thing.


so:

you can't do anything about it, except:

1. avoid that construct. if you have to use variables local to the
page, you should be using %mdat anyway.

2. use [$var$] declarations, since they seem to work.

-- 
 - Gus

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to