Hi all,

Thanks for all the help provided so far in my earlier queries. I have a query regarding regexes. I am to match only one specific word in a wordlist which has only those alphabets which it contains and none other than that.

For example:

My Wordlist contains:

alpha
alpha1
beta
betaze
gamma
gamman
gammano

I want to match any scrambled word with a word in the wordlist which has exactly the same alphabets may be unscrambled/scrambled no other alphabets. Say, If I enter 'ammag' (scrambled word for gamma), it should only match 'gamma' and NOT 'gamman' | 'gammano'(which my current code is doing).

Here is the code:
-----------------
use strict;
use warnings;

my($a,$b,$c,$d,$e,$f);
while(1)
{
print "Enter a word: ";
my $this=<STDIN>;
chomp($this);
($a,$b,$c,$d,$e,$f)=split('',$this);
open (FH,'wordlist.txt');
while (<FH>)
{
if (($_=~ /$a/) && ($_=~ /$b/) && ($_=~ /$c/) && ($_=~ /$d/) && ($_=~ /$e/) && ($_=~ /$f/))
{print $_;}
}
close FH;
}
-------------------------------

The wordlist contains even 5/6/7 alphabet words.My second thought on this is that may be I also need to determine length of the words and accordingly, build up the search criteria, so to match exactly the same length of word in the wordlist.

Any suggestions?

Thanks

--
Gunwant Singh.

"What is the sound of Perl? Is it not the sound of a wall that people bang their heads against?"


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to