in reply to splitting a string on a reqexp

@li=split (\d\), $l);#  - escaping the )

You need to enclose your regex in slashes /.../

Replies are listed 'Best First'.
Re^2: splitting a string on a reqexp
by chrestomanci (Priest) on Nov 29, 2010 at 12:34 UTC

    It is possible to delimit regular expressions with other chars, and I though that perhaps the OP was stumbling over this feature of perl, and accidentally using round brackets as a delimiter, so I did a quick test

    split ( ), '48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21' split m( ), '48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21' split qr( ), '48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21'

    The second two expressions split the list, but without anything to tell perl that the first is a regular expressions it was not treated as one. I also tried:

    split (\s+), '48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21'

    But that resulted in a syntax error unrelated to split.

      FWIW split ( ), 'a b c' is parsed as split(), 'a b c '. So it's a call to split with no arguments. That call is part of a list, and the string literal is the last part of the list. Certainly not what the OP wants.