[tpm] Weird arrary reference bahaviour

Fulko Hew fulko.hew at gmail.com
Wed Oct 31 17:13:55 PDT 2007


On 10/31/07, Indy Singh <indy at indigostar.com> wrote:
>
> Hi Guys,
> Can anyone explain, why taking a reference to an array gives a different
> value on each iteration of this loop.  This is the line of code:
>   my $r = \@f;
>
> If I move the "my @a" declaration outside the loop I get the same value
> each time.
>
> It seems that on each iteration of the loop a new @f array is created.
> Does that make sense?


... snip ...

foreach $x (@foo) {
>   my @f;


... snip ...

Yes, this make sense because my @f is a variable declared
every time the body of the foreach loop is executed.
(for the same reason that the split is executed every
time through the loop too.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/toronto-pm/attachments/20071031/39c846ee/attachment.html 


More information about the toronto-pm mailing list