At 05:59 PM 05/05/2002, you wrote:
>Hi Steve,
>
>This may not be the most eficient way, but it seems to work.
>
>Someone will undoubtedly offer another (probably better) way to do it.

This is good, but more than necessary...

>Toby
>
><snip>
>my @numbers = qw(01 02 03 03 05 08 09 12 14 13 11 18 17 12 15 16 15 16 12 13
>14 16 17 22 23 24 25 25 23 22 21 20);
>my %counts;


for my $num ( @numbers ) {
        $counts{$num}++;
}

for my $num ( sort keys %counts ) {
        print "There were $counts{$num} occurences of $num\n";
}

Notably, no need to check for the existence of the hash element before incrementing 
it, even with strict.

>&occur_in_array(\@numbers);
>
>sub occur_in_array
>{
>        my $aRef = shift;
>        
>        foreach (@$aRef)
>        {
>                if (!exists($counts{$_}))
>                {
>                        $counts{$_} = 1;
>                }
>                else
>                {
>                        $counts{$_}++;
>                }
>        }
>        
>}
>
>while (($key,$value) = each %counts)
>{
>        print "$key = $value\n";
>}
></snip>
>
>-----Original Message-----
>From: steve silvers [mailto:[EMAIL PROTECTED]]
>Sent: Monday, May 06, 2002 10:51 AM
>To: [EMAIL PROTECTED]
>Subject: Regular Expression
>
>
>I have seen a couple of good regular expression questions asked and 
>answered. Now I have a question. This is probably easy but i'm stuck on it. 
>All I want to do is take.
>
>
>my @numbers = 
>(01,02,03,03,05,08,09,12,14,13,11,18,17,12,15,16,15,16,12,13,14,16,17,22,23,
>24,25,25,23,22,21,20); 
>  so on, could be up to 99. Read them in and get a count of all the numbers.
>
>How many 01 or 17 or 22 there are in the array. I saw an answer for doing 
>this with single numbers such as 2897, but how with double numbers. The out 
>put i'm looking for is similar.
>
>one - however many times.
>two - however many times.
>...
>...
>twenty - however many times.
>...
>...
>
>You get the picture :-)
>
>Any help would be great.
>Thanks in advance. Steve.
>
>_________________________________________________________________
>MSN Photos is the easiest way to share and print your photos: 
>http://photos.msn.com/support/worldwide.aspx
>
>_______________________________________________
>Perl-Win32-Users mailing list
>[EMAIL PROTECTED]
>To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>_______________________________________________
>Perl-Win32-Users mailing list
>[EMAIL PROTECTED]
>To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to