>>I thought that by being declared inside [- -], the subroutine would be
>>recompiled on every request, thus losing any reference to @fields.
>>
No, the reference is not lost, so what Angus wrote about closures was
exactly right.
You should simply pass in the @fields as parameter to your sub or
p to see for sure...
-mp
>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>
IL PROTECTED]
J>Subject: Re: problem with subroutines caching values of variables
J>
J>
J>On Wed, Feb 28, 2001 at 06:08:43PM -, Jonny Cavell wrote:
J>> [-
J>> my @fields = qw(a b);
J>> print OUT "@fields";
J>> sub testingit{
J>> prin
On Wed, Feb 28, 2001 at 06:08:43PM -, 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
The problem arises with subroutines using variables declared at the same
level as the sub, e.g:
[-
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 occasionall