Re: generating a wordlist from an array of arrays



On Sep 29, mark berger said:

hey list. i stuck with gererating a wordlist from a changing
multidimensional array. each entry in the array contains a list with the
possible values.

You want a "cartesian cross product". And there's a module out there that does just that: Set::CrossProduct.


  http://search.cpan.org/~bdfoy/Set-CrossProduct-1.6/CrossProduct.pm

Sample use:

  use Set::CrossProduct;

  my $iterator = Set::CrossProduct->new(['a','b'],['c'],['d','e','f']);

  my @wordlayout = $iterator->combinations;

@wordlayout will be an array of array references (like ['a','c','f']). To turn them into strings, you could do:

  my @wordlayout = map join("", @$_), $iterator->combinations;

any hints on how to solve this? probably using recursion but i got no
idea about it right now. and sorry for my bad english, hope i can make
my problem understandable.

It would be a fun exercise to do this on your own, and yes, recursion is the most obvious way to do it.


--
Jeff "japhy" Pinyan        %  How can we ever be the sold short or
RPI Acacia Brother #734    %  the cheated, we who for every service
http://www.perlmonks.org/  %  have long ago been overpaid?
http://princeton.pm.org/   %    -- Meister Eckhart
.



Relevant Pages

  • Re: This question seems simpler than it actually is...
    ... find a lot of logic designers forget what HDL stands for... ... For the exercise I went ahead and did this with a 6 element array. ... type invect is array of entry; ... case mystate is ...
    (comp.lang.vhdl)
  • Re: A critique of test-first...
    ... > silly to give a coding test to people of our level; ... Each message will have the cummulative probability. ... To find a random message get a number from randand find the entry ... Use a sparse/dense array of chars. ...
    (comp.programming)
  • Re: A critique of test-first...
    ... > silly to give a coding test to people of our level; ... Each message will have the cummulative probability. ... To find a random message get a number from randand find the entry ... Use a sparse/dense array of chars. ...
    (comp.programming)
  • Re: Removing entry from @rray
    ... For some time I have been using two different method for removing an entry ... and places each line into the array. ... Redefining the @array element inside to loop ...
    (comp.lang.perl.misc)
  • Re: Framework 2.0 array redim unsatisfactory performance
    ... Not a surprise, most likely it is implemented as single-linked ... Implements the System.Collections.Generic.IListinterface using an array ... How are you determining "at least 5 additional bytes for each entry"? ... | The reason why I test Array is because I need a dynamic data structure ...
    (microsoft.public.dotnet.languages.vb)