On Thu, Aug 01, 2002 at 06:02:14PM -0400, Miko O'Sullivan wrote:
> This is a small collection of ideas for the Perl6 language. Think of this
> posting as a light and refreshing summer fruit salad, composed of three
> ideas to while away the time during this August lull in perl6-language.
>
>
> --------------------------------------------------------
> Give split an option to keep the delimiters in the returned array
>
> I often find that I want to split an expression, but I don't want to get rid
> of the delimiters. For example, I've been parsing a lot of SQL lately, and
> I find myself needing to split expressions like this:
>
> rank=?
>
> It would be really groovy if that expression could be split with the
> delimiters in place, something like this:
>
> @tokens = split _/[?=*-+]/, $sql, keep=>'all';
Try using
@tokens = split /([?=*-+])/, $sql;
> and get back an array with these values: ('rank', '=', '?')
>
> But that raises a problem: what if the expression is this (note the spaces):
>
> rank = ?
>
> In that case I would want the = and ? but I wouldn't want the spaces. A
> slightly different option could keep just stuff in parens:
>
> @tokens = split /\s*([?=*-+])\s*/, $sql, keep=>'parens';
@tokens = split /\s*([?=*-+])\s*/, $sql;
already does, in perl 5, what you want.
Graham.