Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Count of array value into hash

by prasadbabu (Prior)
on Jul 12, 2006 at 11:17 UTC ( [id://560665]=note: print w/replies, xml ) Need Help??


in reply to Count of array value into hash

Anonymous Monk Try this.

use strict; use warnings; use Tie::IxHash; my (%hash1); tie %hash1, "Tie::IxHash"; #To maintain the order my @array = ("one", "two", "one", "three", "four", "one", "two"); $hash1{$_}++ for (@array); my $hash = \%hash1; print "$_ => $hash->{$_}\n" for ( keys %{$hash}); #Dereference and pri +nt outputs: -------- one => 3 two => 2 three => 1 four => 1

I have used Tie::IxHash to maintain the insertion order, if order is not a matter, you can just ignore that. Also tak a look at hash and perlref.
shmem++

updated:

Prasad

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://560665]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-24 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found