I almost feel abusive asking for this here on the SDMB since it’s totally not a general interest question. On the other hand there’s an expert on everything here and we’re all generally much nicer to Perl newbies… can someone give me a hand with what I think is a simple, basic, God-I-feel-stupid-for-having-to-ask problem with Perl?
If I have this hash:
%HoA = (
flintstones => [ "fred", "barney" ],
jetsons => [ "george", "jane", "elroy" ],
simpsons => [ "homer", "marge", "bart" ],
);
Then something like print scalar (keys %HoA) gives me the number of keys. Easy enough – %HoA refers to the hash as a hash. If I do this:
my $flints = $HoA{'flintsones'};
Then $flints contains a reference to the array “contained” in the value for key “flintstones”, right? That is, key “flintstones” can only be scalar, so it contains the address of the array. So I should be able to use the array pointed to by $flints as @flints, isn’t that correct? So I should be able to do something like print scalar @flints to get the array size. That doesn’t work, though.
By extension, I think I should be able to
print $flints[0];
…in order to print “fred” – also fails.
I’ve read all kinds of documentation about references in Perl, and it’s just flying way over my head, which is odd because I do perfectly fine in Object Pascal, C, and Objective-C with pointers and handles. Weird.
Could someone provide me with an example on how to access the data in the structure above? Nothing I’ve read addresses such a structure. Also if the example isn’t totally obvious, could you break it down for me? I hate to sound like such a noob, but this is really frustrating me. This is Perl 5.003 BTW (old, old stuff on old, old machines).