Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- my $word = shift @ARGV;
- my $wordlen = length($word);
- my $word2;
- if (!@ARGV) {
- $ARGV[0] = '/usr/share/dict/words';
- }
- while ($word2=<>) {
- chomp $word2;
- my $lendif = length($word2)-$wordlen;
- if ($lendif == 0) {
- $chardif = $word ^ $word2;
- if ($chardif =~ tr/\0//c == 1) {
- print $word2."\n";
- }
- } elsif ($lendif == -1 or $lendif == 1) {
- my($longer, $shorter) = $lendif == 1 ? ($word2, $word) : ($word, $word2);
- for my $index (0..length($longer)-1) {
- if(substr($longer,0,$index).substr($longer,$index+1) eq $shorter) {
- print $word2."\n";
- last;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement