in reply to Find all string permutations
use Algorithm::Loops qw( NestedLoops ); my $pat = '{a|b}cd{f|g|h}'; my @loops; for ($pat) { if (/\G ( [^{]+ ) /xgc) { push @loops, [ $1 ]; redo; } if (/\G \{ ([^}]*) \} /xgc) { push @loops, [ split /\|/, $1, -1 ]; redo; } } NestedLoops(\@loops, sub { print(@_, "\n"); });
acdf acdg acdh bcdf bcdg bcdh
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Find all string permutations
by Gangabass (Vicar) on Apr 27, 2010 at 00:13 UTC |