in reply to Re: Not quite a simple split
in thread Not quite a simple split

I don't understand. As I read it, the split will take whitespace and a quoted string as the delimiter. So it will return all the tokens that are not quoted strings. I guess the undef return has to do with matching multiple times in the same gap? I thought split was specifically supposed to not do that.

Replies are listed 'Best First'.
Re: Re: Re: Not quite a simple split
by Zaxo (Archbishop) on Feb 01, 2004 at 23:36 UTC

    I think you missed the '?' quantifier after the quoted-string group. It is allowed to be absent, so the split will accept whitespace alone. It also eats trailing whitespace after a quoted section.

    The captured string between the quotes is the only element of the regex that is passed into the list result of split. If there is no quoted string, that capture is present, but undef. Hence the grep filter.

    After Compline,
    Zaxo

      Actually, I missed the significance of a capture group in the split. So it returns the tokens which as I indicated will be everything except the quoted ones, but then the capture group makes it return the delimter too which will be the quoted strings.