Guest User

Untitled

a guest
Dec 11th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use File::Slurp qw(read_file);
  5.  
  6. my ($total, $suffix, @dictionary, @_dictionary, @failed);
  7.  
  8. $suffix = $ARGV[0];
  9.  
  10. @dictionary = read_file("./Etcetera/sowpods.txt") or die "couldn't open dictionary $!";
  11.  
  12. BEGIN { $total = 0; }
  13. END {
  14. print "\n\n---------------\ntotal:\t$total\n";
  15. print "failed:\t@failed\n" if @failed;
  16. }
  17.  
  18. @_dictionary = grep /$suffix$/, @dictionary;
  19.  
  20. foreach ("a".."z") {
  21. my ($prefix, @matches, @sorted, $longest);
  22.  
  23. $prefix = $_;
  24. @matches = grep /^$prefix/, @_dictionary;
  25.  
  26. if (@matches) {
  27. @sorted = sort { length($b) <=> length($a) } @matches;
  28. $longest = $sorted[0];
  29. chomp $longest;
  30. my $score = length($longest);
  31.  
  32. $total += $score;
  33.  
  34. print "$score\t$longest\n";
  35. } else {
  36. push @failed, $prefix;
  37. }
  38. }
Add Comment
Please, Sign In to add comment