Choosing grouping of split items

From: fishfry (BLOCKSPAMfishfry_at_your-mailbox.com)
Date: 02/15/04


Date: Sun, 15 Feb 2004 08:29:25 GMT

If I have

  $text = 'abc - def - ghi - jkl";

then

    @tokens = split(/-/, $text, 3);

splits the line into abc, def, ghi - jkl (ignoring leading and trailing
spaces).

I have an application where there may be 3 or 4 items separated by '-'
but if there are 4, I want them returned as abc - def, ghi, and jkl.

Is there a one-liner for that?



Relevant Pages