tlemons has asked for the wisdom of the Perl Monks concerning the following question:
I'm using the following code to process lines in the $discovered array, and create a number of hashed pairs in the same array row. The code works well.
until ($discovered[$i] eq ""){ ($key, $value) = split /:\s*/, $discovered[$i]; $arrayAoH[$j]{$key} = $value; $i++; }
But, when I enabled 'use strict' in my code, I get the following error when the line containing '$arrayAoH[$j]{$key} = $value;' is executed:
"Can't use string ("") as a HASH ref while "strict refs" in use at xxx.pl"
I've pored over the examples in 'Programming Perl', and have Google'd a bit. But I just don't understand why that line is wrong, and what I should do to fix it.
I tried using the following line in place of the offending line:
$arrayAoH[$j] = { $key => $value };
but it creates an array row with only a single has (whatever the last has processed was).
Thoughts, please!
Thanks tl
20050623 Edit by ysth: code tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array of hashes reference problem
by tlm (Prior) on Jun 22, 2005 at 17:34 UTC | |
by tlemons (Novice) on Jun 22, 2005 at 17:52 UTC | |
by rev_1318 (Chaplain) on Jun 22, 2005 at 18:15 UTC | |
by tlemons (Novice) on Jun 22, 2005 at 18:30 UTC | |
by Errto (Vicar) on Jun 23, 2005 at 03:06 UTC | |
|
Re: Array of hashes reference problem
by injunjoel (Priest) on Jun 22, 2005 at 18:04 UTC | |
by tlemons (Novice) on Jun 22, 2005 at 18:20 UTC | |
by sapnac (Beadle) on Jun 22, 2005 at 19:09 UTC | |
by tlemons (Novice) on Jun 22, 2005 at 19:38 UTC | |
by sapnac (Beadle) on Jun 22, 2005 at 20:32 UTC | |
| |
by djohnston (Monk) on Jun 22, 2005 at 20:29 UTC |