in reply to Combinatorics problem

say"@$_"for(*_=sub{!@_?():@_==1?map{[$_]}@{$_[0]}:map{my$x=$_;map{[$x, +@$_]}_(@_[1..$#_])}@{$_[0]}})->([1,2],["a","b"],["#","*","&"]); __END__ 1 a # 1 a * 1 a & 1 b # 1 b * 1 b & 2 a # 2 a * 2 a & 2 b # 2 b * 2 b &

Replies are listed 'Best First'.
Re^2: Combinatorics problem
by JavaFan (Canon) on Sep 04, 2009 at 07:45 UTC
    The code above contains a bug - it returns an empty list when no arguments are given, but it should return a reference to an empty list. Fixing the bug also means the code can be shortened:
    say"@$_"for(*_=sub{@_?map{my$x=$_;map{[$x,@$_]}_(@_[1..$#_])}@{$_[0]}: +[]})->([1,2],["a","b"],["#","*","&"]);