Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: split string on plus sign
by svenXY (Deacon) on Sep 18, 2008 at 14:06 UTC
    my @fields = split(/\+/, $string);

    Regards,
    svenXY
Re: split string on plus sign
by lamp (Chaplain) on Sep 18, 2008 at 14:40 UTC
    refer split documentation for more information.
Re: split string on plus sign
by JadeNB (Chaplain) on Sep 18, 2008 at 20:42 UTC
    As an elaboration on svenXY's answer: Presumably your problem is that you tried split /+/, $string and got the complaint Quantifier follows nothing in regex …. That's because + has special meaning to the regex engine ("one or more of the preceding …"), so you need to escape it with a backslash to remove its special meaning. That gives split /\+/, $string, as indicated. See Regular Expressions for more details on special characters (and a lot of other things).

      To further elaborate ... the first parameter to split() is always a regular expression (except the split ' ',... special case). Even if you enclose the parameter in quotes. So even split '+', $string emits that error message. IMHO, it's bad design, but that's the way it is. If you do want to split on a literal string and not have to worry about special characters you have to use split /\Q$separator\E/, $string.