in reply to problem in splitting on special character

The first argument of split is either a compiled regexp or a regexp string. | is a special character in regular expressions, so it must be escaped if you mean it literally.

Some solutions:

split(/\|/, ...)
my $re = qr/\|/; split($re, ...)
my $re = "\\|"; # \| split($re, ...)
my $str = "|"; # | my $re = quotemeta($str); # \| split($re, ...)

In your case, the last alternative is the desired one. You want to convert a text into a regexp, and quotemeta will do that for you.

my $sep = $arr[2]; split(quotemeta($sep), ...)

Replies are listed 'Best First'.
Re^2: problem in splitting on special character
by denzil_cactus (Sexton) on Aug 30, 2007 at 05:41 UTC
    hey Thanx to both of you...