erwan has asked for the wisdom of the Perl Monks concerning the following question:
Hi everyone,
Can anyone help me understand what happens here:
version 1:
map { die "bug before!" if (!defined($_)); } values %{$self->{docs}}; my @docsObservs = map { $_->getObservations() } values %{$self->{docs} +}; map { die "bug after!" if (!defined($_)); } values %{$self->{docs}}; print "ok\n";
result:
bug after! at .....
Version 2:
map { die "bug before!" if (!defined($_)); } values %{$self->{docs}}; my @docsObservs; foreach my $docP (values %{$self->{docs}}) { push(@docsObservs, $docP->getObservations()); } map { die "bug after!" if (!defined($_)); } values %{$self->{docs}}; print "ok\n";
result:
ok
This is just one part of a quite big program that I'm in the process of debugging, so I certainly still have bugs. But I'm puzzled by the fact that switching from version 1 to version 2 (without any other change) solves the issue. I can happily use version 2 of course, but I can't see what is wrong in the first version and I don't like that ;) Any idea?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strange bug with map
by Anonymous Monk on Feb 11, 2016 at 00:01 UTC | |
by NetWallah (Canon) on Feb 11, 2016 at 00:55 UTC | |
|
Re: Strange bug with map
by erwan (Sexton) on Feb 11, 2016 at 16:04 UTC | |
by choroba (Cardinal) on Feb 11, 2016 at 16:08 UTC | |
by erwan (Sexton) on Feb 11, 2016 at 16:19 UTC | |
by erwan (Sexton) on Feb 11, 2016 at 16:17 UTC |