in reply to Can't use string ("query") as an ARRAY ref error
"@{ $hash{$query} }" means "the array referenced by the reference stored in $hash{$query}". However, $hash{$query} does not contain a reference to an array. It contains the string "query".
If $hash{$query} is undefined and @{ $hash{$query} } is used as an lvalue (like when it's an argument to push), an array will automatically be created and a reference to that array will be stored in $hash{$query}. This is called autovivification.
Get rid of the line $hash{'query'}= $query; (to allow autovivification).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can't use string ("query") as an ARRAY ref error
by Anonymous Monk on Aug 28, 2009 at 01:18 UTC | |
by ikegami (Patriarch) on Aug 28, 2009 at 02:49 UTC |