Advertisement
faubiguy

wordchange.pl

Jul 29th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.61 KB | None | 0 0
  1. #!/usr/bin/perl
  2. my $word = shift @ARGV;
  3. my $wordlen = length($word);
  4. my $word2;
  5.  
  6. if (!@ARGV) {
  7.     $ARGV[0] = '/usr/share/dict/words';
  8. }
  9.  
  10. while ($word2=<>) {
  11.     chomp $word2;
  12.     my $lendif = length($word2)-$wordlen;
  13.     if ($lendif == 0) {
  14.         $chardif = $word ^ $word2;
  15.         if ($chardif =~ tr/\0//c == 1) {
  16.             print $word2."\n";
  17.         }
  18.     } elsif ($lendif == -1 or $lendif == 1) {
  19.         my($longer, $shorter) = $lendif == 1 ? ($word2, $word) : ($word, $word2);
  20.         for my $index (0..length($longer)-1) {
  21.             if(substr($longer,0,$index).substr($longer,$index+1) eq $shorter) {
  22.                 print $word2."\n";
  23.                 last;
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement