cholt has asked for the wisdom of the Perl Monks concerning the following question:
Does anyone know why this happens?
In perl 5.8.8 I came across a bug after much trouble with some code.
If I have the following data structure:
$test = [{augustus => ''}];
and then do the following:
each %{$test};
I get the error "Bad index while coercing array into hash", which is correct. However if I have the slightly modified data structure:
$test = [{augustus => []}];
Then this works:
each %{$test};
It produces no error, and can result in a huge weird array that fills up large chunks of memory, and is difficult to find when debugging.
I have verified this on 5.8.8 and 5.8.9 on both Linux and Mac OSX.
Perl 5.10.0 at least throws a "Not a HASH reference" error.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: can coerce array into hash
by JavaFan (Canon) on Dec 01, 2010 at 21:22 UTC | |
|
Re: can coerce array into hash
by ikegami (Patriarch) on Dec 01, 2010 at 19:52 UTC |