in reply to Re: Decompose a String into Tuples (Faster and Compact Way)
in thread Decompose a String into Tuples (Faster and Compact Way)
Here's my shifty suggestion:
update: shorter and generalizable to producing any size tuple:sub decomp { @_ = split / /, shift; return [ map { join " ", (shift, shift, $_[0]) } (1..@_/2) ]; }
sub decomp { my $n = 2; # for n+1-uples @_ = split / /, shift; return [ map { $_*=$n; "@_[$_..$_+$n]" } 0..@_/$n-1 ]; }
|
|---|