in reply to Counting elements in array and outputing the count and item
Tried and tested:
use strict; use Data::Dumper; # original data my @status = ( "Applied", "Enrolled", "Admitted", "Applied", "Enrolled" ); # count keys my %tmphash = (); $tmphash{$_}++ for ( @status ); # convert into an array, as requested my @statuscount = %tmphash; # display print( Data::Dumper::Dumper( \@statuscount ) );
Outputs:
$VAR1 = [ 'Admitted', '1', 'Enrolled', '2', 'Applied', '2' ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Counting elements in array and outputing the count and item
by dmaranan (Acolyte) on Jun 17, 2008 at 18:44 UTC | |
by wfsp (Abbot) on Jun 18, 2008 at 06:26 UTC |