in reply to Strange bug with map
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}};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Strange bug with map
by choroba (Cardinal) on Feb 11, 2016 at 16:08 UTC | |
by erwan (Sexton) on Feb 11, 2016 at 16:19 UTC | |
|
Re^2: Strange bug with map
by erwan (Sexton) on Feb 11, 2016 at 16:17 UTC |