I think split behaves differently if the first parameter is a normal string instead of a regex. The perlfunc documentation doesn't mention this and I can't remember how exactly it differs. Anyway since | is a regex special character (alternation) you need to escape it. I'd normally write this as:
split /\|/, $strThe reason you need two \s is because of the behaviour of double quotes - just try:
print "|"; print "\|"; print "\\|";
and you should see what's happening.
In reply to Re: Surprised by split
by muntfish
in thread Surprised by split
by GrandFather
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |