Hi all

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.

I need another approach (code) to do the same things


#!/usr/bin/perl -w

my %freq;
while( my $line = <STDIN> ){
        foreach my $w ( split( /\s+/, $line ) ){
                if( exists $freq{$w} ){ 
                        $freq{$w}++; 
                }else{
                        $freq{$w} = 1;
                }
        }
}

foreach my $k ( keys( %freq ) ){
        print "$k $freq{$k}\n";
} 




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



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

Reply via email to