good evening list.
thanks for the replies and sorry that i couldn't find the time to reply
sooner. sadly i'm still in a rush and haven't tried all of your
solutions, hope i will get to it soon. for now i just go with one, so i
can get the stuff i wanted to work.
still curious about the other through, especially the recursive one.
never quite get this kind of proposal the fast way. but i will check it
out soon.
Christer Ekholm schrieb:
> mark berger <[EMAIL PROTECTED]> writes:
> ...
>>the only thing i came up with so far, is to generate some for loops
>>based on the array structure (how many chars, with how many posible
>>values) on fly and pass this to eval. pretty ugly (at least the way i
>>thought it out).
>
>
> I gave that some thought. And I think it actually might be a good
> solution. I wonder which method is more efficient, dynamic
> code-generation or recursion?
>
> Here is my try at it, does it look like yours?
>
> ...
i used your version, because for me it was the most straight forward
approach, kind of where i wanted to go when i first thought about it.
and no, it doesn't looked like mine at all. source scribble are gone but
i tried to put the string together with indexes not concatenating and it
was such mess.
i tried to modify your example so it will also handle variable length
"pieces", and it seems to work too:
@wordlayout =
(
['aa', 'A'],
['b', ''],
['c','', 'd', 'DD'],
);
for my $idx ( 0 .. $#wordlayout ) {
# A loop for each level.
$code .= 'for my $char ( @{$wordlayout['.$idx.']} ) {'."\n";
# concat chars
$code .= '$str .= $char;'."\n";
}
# At the innermost level, extract a word.
$code .= 'push @list, $str;'."\n";
for my $idx ( 0 .. $#wordlayout ) {
# Remove this levels char on our way out.
$code .= 'my $len = length $char;'."\n";
$code .= 'substr($str, \'-\'.$len, $len,"");'."\n";
$code .= "}\n";
}
# curious?
# print $code;
# Now do it.
eval $code;
# The result is in @list.
print join("\n",@list),"\n";
results:
aabc
aab
aabd
aabDD
aac
aa
aad
aaDD
Abc
Ab
Abd
AbDD
Ac
A
Ad
ADD
thanks again to all of you, for taking the time to answer.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>