in reply to cartesian product preserving order

glob can do that,

my $combs = [ map { [split //] } glob '{a,b,c}{1,2,3}{-,+,\*}' ];

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: cartesian product preserving order
by Anonymous Monk on Jun 09, 2005 at 07:07 UTC
    Wow! Just wow! However, this solution seems not to cope with strings of arbitrary length. So I did some cargo cult programming and "invented" the delimiter.
    my $combs = [ map { [split /\./] } glob '{CZK,EUR}.{asia,emea,na,sa}.{acad,sopr,user}' ];
    But it feels like I brought some kludginess to the code that way. Punymonk

      That's exactly how I would have handled longer elements. You can pick any seperator that suits the data.

      That's not cargo cult, it's adaptation. Glad you like it :-)

      After Compline,
      Zaxo

Re^2: cartesian product preserving order
by wazoox (Prior) on Jun 09, 2005 at 12:15 UTC
    Too bad the other usage of glob (out of file name expansion) aren't documented in the standard documentation...

      It's documented indirectly. perldoc -f glob says that glob expansion works as in csh. Try this in csh or bash:

      $ echo {a,b,c}{1,2,3} a1 a2 a3 b1 b2 b3 c1 c2 c3 $

      After Compline,
      Zaxo

        So you're also a shell demon? congratulations :)