Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- %word_hash = ();
- @common_words = ('the', 'be', 'to', 'of', 'and', 'in', 'that', 'have',
- 'it', 'for', 'not', 'on', 'with', 'he', 'as', 'is',
- 'was', 'are', 'you', 'do', 'at', 'had', 'i', 'a', 'has',
- 'from', 'an', 'his', 'hers', 'but', 'said', 'him', 'her',
- 'they', 'them', 'or', 'am', 'did');
- while ($string = <STDIN>)
- {
- foreach (@common_words)
- {
- $string =~ s/\b$_\b//gi;
- }
- foreach $word (keys(%word_hash))
- {
- if ($string =~ s/\b$word\b//gi)
- {
- $word_hash{$word}++;
- }
- }
- foreach $word (split /\W/, $string)
- {
- $word_hash{ lc($word) } = 1;
- }
- }
- foreach $key (sort {$word_hash{$b} <=> $word_hash{$a}} keys%word_hash)
- {
- print "$key : $word_hash{$key}\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement