in reply to creating word from array of array

Let's generalize a little and allow more than one set of variant characters.
#!/usr/bin/perl -w use strict; # Set up my @charsets = ( [ "b", "h" ], [ "e" ], [ "l", "p", "i" ], [ "l" ], [ "o" ], ); # Do it my @words = (""); for my $char_ref (@charsets) { my @temp_words; for my $word_part (@words) { for my $char (@$char_ref) { push @temp_words, $word_part . $char; } } @words = @temp_words; } # Show it print "$_\n" for @words;
This prints:
  bello
  beplo
  beilo
  hello
  heplo
  heilo

------------------------------------------------------------
"Perl is a mess and that's good because the
problem space is also a mess.
" - Larry Wall

Replies are listed 'Best First'.
Re: Re: creating word from array of array
by smgfc (Monk) on Feb 17, 2002 at 00:19 UTC
    hey, this is exactly what i was looking for, i should have made it clear there could be more then one "set of variant characters" (right now i am allowing up to three). Thanks again!