in reply to Python to perl: itertools product to replace a char in string in each possible position
DB<123> $input="one two three" => "one two three" DB<124> $globber= join q|{' ','-'}| , split / +/, $input => "one{' ','-'}two{' ','-'}three" DB<125> print "$_\n" while glob($globber) one two three one two-three one-two three one-two-three
please note that line 125 acts as an iterator looping over all results, like yield permits.
for a flat list result just don't call glob in scalar context:
DB<127> print join "\n", glob($globber) one two three one two-three one-two three one-two-three
just in case $input includes any meta characters or wildcards, you'll need to escape them before.
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
|
|---|