[tpm] Weird arrary reference bahaviour

Indy Singh indy at indigostar.com
Wed Oct 31 16:53:44 PDT 2007


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?

Indy Singh
IndigoSTAR Software -- www.indigostar.com


my @foo = ("ford:ltd", "chevy:nova");
my $x;
my @a;

foreach $x (@foo) {
  my @f;
  @f = split(/:/, $x);
  my $r = \@f;
  print "r = $r\n";
  push @a, $r;
}

my $item;
foreach $item (@a) {
  print join(' ', @{$item}),"\n";
}



More information about the toronto-pm mailing list