in reply to Find all string permutations

For ...um ... nFor.

#! perl -slw use strict; sub nFor(&@) { my $code = shift; die "First argument must be a code ref" unless ref( $code ) eq 'CO +DE'; my @limits = @_; my @indices = ( 0 ) x @limits; for( my $i = $#limits; $i >= 0; ) { $i = $#limits; $code->( @indices ), ++$indices[ $i ] while $indices[ $i ] < $limits[ $i ]; $i = $#limits; $indices[ $i ] = 0, ++$indices[ --$i ] while $i >= 0 and $indices[ $i ] == $limits[ $i ]; } } our $TMPL //= '{a|b}cd{f|g|h}'; my @as = map { /\|/ ? [ split '\|', $_ ] : length() ? [$_] : (); } split '\{([^}]+)\}', $TMPL; nFor { print join '', map $as[ $_ ][ $_[ $_ ] ], 0 .. $#_ } map scalar @$_, @as; __END__ [ 1:50:21.76] C:\test>junk43 -TMPL="{a|b}def{g|h}j{K|l}m{n|o}p{q|r}" adefgjKmnpq adefgjKmnpr adefgjKmopq adefgjKmopr adefgjlmnpq adefgjlmnpr adefgjlmopq adefgjlmopr adefhjKmnpq adefhjKmnpr adefhjKmopq adefhjKmopr adefhjlmnpq adefhjlmnpr adefhjlmopq adefhjlmopr bdefgjKmnpq bdefgjKmnpr bdefgjKmopq bdefgjKmopr bdefgjlmnpq bdefgjlmnpr bdefgjlmopq bdefgjlmopr bdefhjKmnpq bdefhjKmnpr bdefhjKmopq bdefhjKmopr bdefhjlmnpq bdefhjlmnpr bdefhjlmopq bdefhjlmopr

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy