Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

RE: permutations?

by sean (Beadle)
on Jun 14, 2000 at 05:06 UTC ( [id://18018]=note: print w/replies, xml ) Need Help??


in reply to permutations?

Hmmm...
my %words = ( 'lng' => ['lang','long','leng','loo'], 'sentance' => ['sentence'], 'thxs' => ['this','thus'] ); my @results; for my $key (keys %words) { if (defined(@results)) { @results = &loljoin(\@results, $words{$key}); } else { @results = map {[$_]} @{$words{$key}}; } } sub loljoin { #pass me two references to arrays: my @results = @{(shift)}; #the results so far.. my @newwords = @{(shift)}; #and the set to add to our results my @newresults; for my $word (@newwords) { for my $result (@results) { push(@newresults,[@$result, $word]); } } return @newresults; } # results are in @results as a list of lists # eg: for my $foo { print join(" ",@$foo) . "\n" }
Hmm, well. That appears to work, but it doesn't look as good as it could.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2024-03-28 10:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found