in reply to Re: splitting a string on a reqexp
in thread splitting a string on a reqexp

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.

Replies are listed 'Best First'.
Re^3: splitting a string on a reqexp
by moritz (Cardinal) on Nov 29, 2010 at 12:48 UTC

    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.