jdhedden has asked for the wisdom of the Perl Monks concerning the following question:
Running this produces an infinite loop that continually outputs only one value from the hash.use strict; use warnings; package Results; { sub new { return (bless(\do{ my $scalar; }, __PACKAGE__)); } use overload ( '%{}' => \&as_hash ); sub as_hash { return ({ 'key1' => 'value1', 'key2' => 'value2' }); } } package main; my $obj = Results->new(); while (my ($key, $val) = each(%{$obj})) { print("$key => $val\n"); }
Is this a bug?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: overload + each() bug
by borisz (Canon) on Nov 17, 2005 at 15:59 UTC | |
by dragonchild (Archbishop) on Nov 17, 2005 at 16:07 UTC | |
by jdhedden (Deacon) on Nov 17, 2005 at 17:29 UTC | |
by VSarkiss (Monsignor) on Nov 17, 2005 at 16:10 UTC |