Thank you both for your answers. I didn't realize that $_ was not local, that explains it indeed.
But now I have a follow up question: I don't understand why the values in the hash are affected? In my mind I assumed that $_ receives a copy of the ref to the object, so I didn't expect that when $_ is set to undef the values in the hash become undefined as well. Here is an example of what I mean:
It turns out that this version dies with the "bug after" error. Is this somehow related to how the values function works? It looks as if $docP is some kind of "hard link" to the object, and not a simple copy of the ref.my @docsObservs; foreach my $docP (values %{$self->{docs}}) { push(@docsObservs, $docP->getObservations()); die "loop variable is undef after call to getObservations()" if (!de +fined($docP)); $docP = undef; } map { die "bug after!" if (!defined($_)); } values %{$self->{docs}};
In reply to Re: Strange bug with map
by erwan
in thread Strange bug with map
by erwan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |