hihi
Firstl i got most of this code from another person on another forum but I have been trying like crazy to modify it so that it reads a list of scrambled words from a file and outputs the unscrambled words to another file.
scrambled.txt = input file
unscrambled.txt = output file
here is the code:
And I'm pretty new to perl..
thanks allot!
Firstl i got most of this code from another person on another forum but I have been trying like crazy to modify it so that it reads a list of scrambled words from a file and outputs the unscrambled words to another file.
scrambled.txt = input file
unscrambled.txt = output file
here is the code:
Code:
use strict;
use warnings;
#!/usr/local/bin/perl
my $dict = 'wordlist.txt';
my @Unscrambled = ();
# Do not space-separate the word in this version.
my $scrambled_word = shift
or die "Must specify a word\n";
my $scrambled_length = length $scrambled_word;
my $scrambled_sorted = join '', sort split '', $scrambled_word;
my $pattern = qr{
\A
(?:
[$scrambled_word]{$scrambled_length}
)
\n
\z
}x;
open DICT, '<', $dict
or die "Cannot open '$dict': $!";
while () {
next unless /$pattern/o;
chomp;
my $sorted = join '', sort split '', $_;
next unless $sorted eq $scrambled_sorted;
push @Unscrambled, $_;
}
close DICT or warn;
open (MYFILE, '>>data.txt');
foreach (@Unscrambled) {
print MYFILE "$_";
}
close (MYFILE);
thanks allot!
Comment