http://qs1969.pair.com?node_id=302493


in reply to Re: Re: Help on array element counting
in thread Help on array element counting

# Declare a hash named fruits. A hash contains # { key,value } pairs where the key fields are unique. my %fruits; # Get each element in the @fruits array and assign it to #the { key } portion of the hash. Also, increment the #{ value } part of the hash (the value starts with 0). #This will count the number of times the { key } appears in #the array $fruits{$_}++ for ( @fruits ); #Declare variables for { key, value } my ( $fruit, $count ); #Get each { key, value } pair and assign them to #{ fruit, count } for ( $fruit, $count ) ( each %fruits ) { #Print out the number of times the fruit existed. print "$fruit => $count\n"; }