CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Word Unscrambler


New User

Jun 8, 2008, 10:54 PM

Post #1 of 4 (1065 views)
Word Unscrambler Can't Post

Hello, I am new to programming and am trying to write a program that reads in 10 scrambled words, unscrambles them, and prints them to the monitor. I borrowed code from a different unscrambling program and have been trying to modify it to suit my needs:


#Opens a file containing scrambled words and reads words into an array
$file = '/home/****/Perl/words';
open(INFO, $file);
@words = <INFO>;

#"wordlist" is a dictionary
my $dict = '/home/****/Perl/wordlist';

#for every word in array
foreach $word(@words)
#enter characters into an array
my @chars = split("", $word);

$word = "";
@chars = sort (@chars); #sorts chars by alphabetical order
foreach (@chars) {
$word .= $_;
} #algorithm incomplete
$word =~ $dict;
print "$word,";
#Need to find a way to continue to the next word if the condition is met
print "\n";

My problems so far are that I believe the algorithm that scrambles the words in every possible order is incomplete and I cannot figure out how to move on to the next word if a dictionary match is found. Any help would be appreciated!



Jun 9, 2008, 3:16 AM

Post #2 of 4 (1054 views)
Re: [cheechand] Word Unscrambler [In reply to] Can't Post

use the List::Permutor module to find all the permutations of the scrambled words

I leave it up to you to figure out how to use it. Your code has more problems though. Like this line is not doing anything at all:

 $word =~ $dict; 

Needs to be wrapped in a conditional:


if ($word eq $dict) }

print "Some cool message";


Is this school work?


Jun 9, 2008, 12:06 PM

Post #3 of 4 (1049 views)
Re: [cheechand] Word Unscrambler [In reply to] Can't Post

This looks like homework, so I'll just give you this hint:

Would a hash like this be helpful to you?

%hash = ( 
a => 'a'
abt => 'bat',
act => 'cat',
dgo => 'dog',
efl => 'elf',
'fgor' => 'frog',

New User

Jun 11, 2008, 8:09 PM

Post #4 of 4 (1040 views)
Re: [meloyelo] Word Unscrambler [In reply to] Can't Post

Hey all,

Just to clarify, this isn't a homework assignment


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives