in reply to Syntax for partly associative arrays

If @a is an array of hashes, you can iterate with,

for (@a) { for (keys %$_) { # ... } }
since the array elements are all hash references.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Syntax for partly associative arrays
by fletcher_the_dog (Friar) on Sep 05, 2003 at 21:04 UTC
    Just to add to what Zaxo said, you'll probably want to use an explicit aliasing variable in your 'for' loops instead of $_ for clarities sake. Something like this:
    foreach my $hash (@a) { foreach my $word (keys %$hash) { my $wordvalue = $hash->{$word}; # ... } }
    Notice that because $hash is a reference to a hash you access its elements via ->{}. In general if you are going to iterate through an array, you want to use 'foreach's aliasing ability to access the elements of the array directly instead of accessing the elements through their indexes.