Richard Heintze wrote:
Is there a way I can explictly declare that each array cell contains a hash?
Here is the only way I know to do it:
my @PCEs=[]; while ($Data->FetchRow()) { my %dh = $Data->DataHash(); $PCEs[$cn]{$dh{"id"}} = $dh{"ridPCE"}; }
This "my" declaration only says that it is an array, not an array of hashes. Can I improve upon this?
Why would you want to declare this? Since the anonymous hashes spring into existence automatically, no declaration is necessary.
To access an element of your referenced hash, you have to add another scalar symbol like this:
$$PCEs[$cn]{$dh{"id"}} ...
Adding an extra $ here causes Perl to look for $PCEs a scalar, which doesn't exist rather than dereference the PCEs array.
Alternatively, you could improve the readability by using the arrow dereference, though:
$PCEs[$cn]->{$dh{"id"}} = $dh{"ridPCE"};
Using the arrow operator is a good idea for readability but isn't related to your extra $ above.
http://danconia.org
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>