Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Simple regex wordlist question

by atemon (Chaplain)
on Sep 11, 2007 at 05:04 UTC ( [id://638225]=note: print w/replies, xml ) Need Help??


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



There are three sides to any argument.....
your side, my side and the right side.

Replies are listed 'Best First'.
Re^2: Simple regex wordlist question
by b4swine (Pilgrim) on Sep 11, 2007 at 05:19 UTC
    This could get awfully slow. 6! is only 720, but if he went to 7! that would be 5040.

    The OP's solution is faster, and ikegami's solution is probably even more so.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://638225]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-19 06:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found