> My code below  does the following :
> - Reads from STDIN
> - Splits the input on whitespace
> - And prints the frequency of terms, with each term printed next to its frequency on 
>STDOUT.

> if( exists $freq{$w} ){ 
>     $freq{$w}++; 
> }else{
>     $freq{$w} = 1;
> }

Increment is magical, if doesn't exist then it is created then incremented :)  That 
means:

$freq{$w}++;

is okay.

You are just processing a list of words, hence this should be okay:

my %freq;
do {
    foreach my $word (split /\s+/, <>) {
        $freq{$word}++;
    }
} until eof;

while (my ($key, $value) = each %freq) {
    print "$key $value\n";
}

Which is a slightly different style that I'd typically would use... but it's nice and 
short, and
you might learn something from it.  :)

Jonathan Paton

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to