On 18 Jun 2001 17:34:29 -0400, David Gilden wrote:
> How about a an example or 2 where you would use this,
> 
> 
> $hash{$_}++
>
<snip />

This is a simple word counting algorhythm.  It might be used to
determine the optimal subset of English (or whatever language) a
foreigner might need to know.

<code>
#!/usr/bin/perl

use strict;

my %word_count;

while (<>) { #read lines from stdin or files named on the commandline
        foreach (split) { #split lines on " "s and loop through them
                $word_count{$_}++; #increment count of word in $_
        }
}

foreach (keys %word_count) { #for each word in word_count
        #print the word and the number of times it occured
        print "$_ occured $word_count{$_} times\n"; 
}
</code>

--
Today is Prickle-Prickle, the 23rd day of Confusion in the YOLD 3167
This statement is false.


Reply via email to