[tpm] Weird arrary reference bahaviour

Indy Singh indy at indigostar.com
Wed Oct 31 17:36:47 PDT 2007


Ok, thanks, I believe you. I just didn't expect that.  I was thinking in C++ terms, where that variable would be declared on the stack frame and would persist until the loop exits.



----- Original Message ----- 
  From: Fulko Hew 
  To: tpm at to.pm.org 
  Sent: Wednesday, October 31, 2007 8:13 PM
  Subject: Re: [tpm] Weird arrary reference bahaviour




  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/7d0df86d/attachment.html 


More information about the toronto-pm mailing list