in reply to Finding the length of an array in a hash of arrays
Yes, because it is called $#{$valid{$key}}. To pick apart, $# gets the index of the last element of an array. The following curlies imply we want to get it from an arrayref. And inside them, we have $valid{$key} which is standard fare.
However your approach is not good Perl. You're iterating over a list; you shouldn't do that with an index variable unless you really need the index number.
foreach my $key (keys %valid) { foreach my $element (@{$valid{$key}}) { print STDERR "$key: $element\n"; } }
And in this case, since you're not sorting the keys or otherwise in need of a specific order, you could use the more efficient each %hash function:
while(my($key, $val) = each %valid) { foreach my $element (@$val) { print STDERR "$key: $element\n"; } }
Makeshifts last the longest.
|
|---|