in reply to Decompose a String into Tuples (Faster and Compact Way)

This is nearly the same as what you're doing. The difference is that you will not start a group with the 2nd item.
sub decomp_str { # Capture three starting with alpha, but advance only one [$_[0] =~ /(?=([a-z]\s*(?:\S+\s*){2}))\S+\s*/gi ] }
Updated, but still untested.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Decompose a String into Tuples (Faster and Compact Way)
by neversaint (Deacon) on Oct 16, 2005 at 03:50 UTC
    Dear Roy Johnson,

    Taking the benefit of incredible speed that your code provide. How can I modify your code above such that given this string:
    my $s1 = 'X -4 Y 3 Z';
    It will decompose into a such AoA:
    $VAR = [["X", -4, "Y"], ["Y",3,"Z"]];
    Thanks so much beforehand. Really hope to hear from you again.

    ---
    neversaint and everlastingly indebted.......
      You just want to split each of the extracted tuple-strings:
      my $aref = [ map [split], $s1 =~ /(?=([a-z]\s*(?:\S+\s*){2}))\S+\s*/gi + ];

      Caution: Contents may have been coded under pressure.