T
Tom
When I run the following:
for($k=0;$k<3;$k++){
$r[$k]->{'NUM'} = $k;
#$temp->{'NUM'} = $k;
#$r[$k] = $temp;
print "added: $r[$k]->{'NUM'}\n";
}
foreach $t (@r){
print "$t->{'NUM'}\n";
}
I get the intended output:
added: 0
added: 1
added: 2
0
1
2
Then I uncomment the commented lines and comment out the
"$r[$k]->{'NUM'} = $k;" line...or, in words, I use a temporary value
to hold the hash before assigning it adding it to the array of hashes.
The output comes out like:
added: 0
added: 1
added: 2
2
2
2
Why is that? I'm probably using scalar assignments when I shouldn't
be, but I don't understand why this happens. How can it be
accomplished with a temporary value?
for($k=0;$k<3;$k++){
$r[$k]->{'NUM'} = $k;
#$temp->{'NUM'} = $k;
#$r[$k] = $temp;
print "added: $r[$k]->{'NUM'}\n";
}
foreach $t (@r){
print "$t->{'NUM'}\n";
}
I get the intended output:
added: 0
added: 1
added: 2
0
1
2
Then I uncomment the commented lines and comment out the
"$r[$k]->{'NUM'} = $k;" line...or, in words, I use a temporary value
to hold the hash before assigning it adding it to the array of hashes.
The output comes out like:
added: 0
added: 1
added: 2
2
2
2
Why is that? I'm probably using scalar assignments when I shouldn't
be, but I don't understand why this happens. How can it be
accomplished with a temporary value?