|
|
| "be consistent" | |
| PerlMonks |
Looping through a hash reference is creating a key...?by the_slycer (Chaplain) |
| on Jun 10, 2004 at 14:05 UTC ( [id://363145]=perlquestion: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.the_slycer has asked for the wisdom of the Perl Monks concerning the following question:
I could swear I've seen this behavior before, but can't find the post. This returns something like:
(before):
$VAR1 = {
1 => {
'foo' => 'bar'
},
2 => {
'foo' => 'bar'
},
3 => {
'foo' => 'bar'
}
};
(after):
$VAR1 = {
1 => {
'foo' => 'bar'
},
2 => {
'foo' => 'bar'
},
3 => {
'foo' => 'bar'
},
4 => {}
};
And I'm not sure why, my question is twofold:1) Is there a good reason why perl creates the reference (4)? 2) Is there a good reason why perl doesn't WARN that I am trying to access a value that doesn't exist? Note that even taking out the || "djkafdkljfa" does not produce a warning The problem is appearing in a bit of code I am developing, and I can get around it, but this tripped me up while I was working on it (using exists($hashref->{key} to determine execution path). ps: Damn, I miss this place, I think it's time to start hanging out here again (especially now that I "do" perl for a living :))
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||