Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.82 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. %word_hash = ();
  4. @common_words = ('the', 'be', 'to', 'of', 'and', 'in', 'that', 'have',
  5.                  'it', 'for', 'not', 'on', 'with', 'he', 'as', 'is',
  6.                  'was', 'are', 'you', 'do', 'at', 'had', 'i', 'a', 'has',
  7.                  'from', 'an', 'his', 'hers', 'but', 'said', 'him', 'her',
  8.          'they', 'them', 'or', 'am', 'did');
  9.  
  10. while ($string = <STDIN>)
  11. {
  12.     foreach (@common_words)
  13.     {
  14.         $string =~ s/\b$_\b//gi;
  15.     }
  16.     foreach $word (keys(%word_hash))
  17.     {
  18.         if ($string =~ s/\b$word\b//gi)
  19.         {
  20.             $word_hash{$word}++;
  21.         }
  22.     }
  23.     foreach $word (split /\W/, $string)
  24.     {
  25.         $word_hash{ lc($word) } = 1;
  26.     }
  27. }
  28. foreach $key (sort {$word_hash{$b} <=> $word_hash{$a}} keys%word_hash)
  29. {
  30.     print "$key : $word_hash{$key}\n";
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement