in reply to How to create multiple keys in a hash
Hi tanuja,
If I understand correctly, you want to count the occurences of elements of a list. If so, this might help.
#!/usr/bin/perl use strict; use warnings FATAL => 'all'; my @colours = ( "red", "green", "yellow", "green", "yellow", "green", + "blue", "red", "green"); my %count; $count{ $_ }++ for @colours; print "$_\t$count{ $_ }\n" for keys %count; __END__ output green 4 blue 1 red 2 yellow 2
Hope this helps
thinker
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How to create multiple keys in a hash
by tanuja (Initiate) on Sep 20, 2003 at 23:32 UTC | |
|
Re: Re: How to create multiple keys in a hash
by Anonymous Monk on Sep 20, 2003 at 23:40 UTC |