tadman has asked for the wisdom of the Perl Monks concerning the following question:
my $foo = { foo => { bar => 'baz' } }; foreach (keys %foo) { if (defined($foo->{$_}->{foo}) && defined($foo->{$_}->{foo}->{bar})) { return $foo->{$_}->{foo}->{bar}; } return; }
Can you spot the error? strict can't. When I run this, I'm into swap space in a matter of seconds, and...then...things...get...very...slow.my $foo = [ { foo => { bar => 'baz' } }, ]; foreach my $foo_entry (@$foo) { foreach (keys %$foo_entry) { if (defined($foo->{$_}->{foo}) && defined($foo->{$_}->{foo}->{bar})) { return $foo->{$_}->{foo}->{bar}; } } return; }
Something is falling through the cracks here, no?my $foo = [ { foo => 'bar' }, ]; foreach my $foo_entry (@$foo) { foreach (keys %$foo_entry) { if (defined($foo->{$_}->{foo}) && defined($foo->{$_}->{foo}->{bar})) { return $foo->{$_}->{foo}->{bar}; } } return; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Automagic Array to Hash Conversion? Pseudo-Hash Explosion
by strat (Canon) on May 14, 2002 at 15:59 UTC | |
Re: Automagic Array to Hash Conversion? Pseudo-Hash Explosion
by Matts (Deacon) on May 14, 2002 at 20:23 UTC | |
Re: Automagic Array to Hash Conversion? Pseudo-Hash Explosion
by ferrency (Deacon) on May 14, 2002 at 18:11 UTC | |
by tadman (Prior) on May 14, 2002 at 18:33 UTC | |
Re: Automagic Array to Hash Conversion? Pseudo-Hash Explosion
by alien_life_form (Pilgrim) on May 14, 2002 at 16:38 UTC | |
Re: Automagic Array to Hash Conversion? Pseudo-Hash Explosion
by Util (Priest) on May 14, 2002 at 18:45 UTC | |
by tadman (Prior) on May 14, 2002 at 20:04 UTC |