in reply to Simple regex wordlist question
Your code is checking each line in the file with the input string. For that another way to do is, get all permutations from the input string, then compare each line in the file with all the permutations you got.
To get all permutations, you can use Math::Combinatorics. Get all permutations into an array and you can use grep to compare.
I have updated your code and is working fine for me. The code I updated is
#!/usr/bin/perl use strict; use warnings; use Math::Combinatorics; #to get all combinations my $input = <STDIN>; my @inputarray = split('',$input); my $file = 'wordlist.txt'; open(INFO, $file); my @lines = <INFO>; close(INFO); my @permutations= map { join "", @$_ } permute(@inputarray );# Get all + permutations of input string my %dup; @dup{@permutations}= (); my @tacobell= grep { exists $dup{$_} } @lines; # Check if any of the c +ombinations exists in file print join ("\n",@tacobell); exit();
Update: Fixed typo.
Cheers !
--VC
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simple regex wordlist question
by b4swine (Pilgrim) on Sep 11, 2007 at 05:19 UTC |