in reply to Curios use of regular expressions in split

See split:

If the PATTERN contains parentheses, additional list elements are created from each matching substring in the delimiter.

So, if you don't want the additional list elements, don't use capturing parentheses. Use noncapturing parentheses (?: ... ) instead.

Replies are listed 'Best First'.
Re^2: Curios use of regular expressions in split
by juliosergio (Sexton) on Feb 15, 2012 at 17:25 UTC

    This doesn't solve my problem, because the matched string isn't stored in $1 ...

      Well, if you want to keep the stuff you split on, use capturing parentheses. If you don't want to keep the stuff, don't use them. $1 is never set, so the way you are trying it will never work.

        First, as you see, from my example, capturing parenthesis do not work, i.e., the string is not splitted according to what I intended to be a separator: 'abc'.

        Second, you said "if you want to keep the stuff you split on"... Yes, this is what I want, but, please don't tell me that "the way you are trying it will never work". Of course, I know that, and this is the reason I'm posting a question here.

        By the way, I'm new here, and I understood this is the site to ask for some help, if it isn't, please tell me where to go with my silly questions.

      This doesn't solve my problem, because the matched string isn't stored in $1 ...

      You were saying?

      @a3 = split /(?:abc)/, "uno abc dos"; print "@a3\n"; __END__ uno dos