in reply to Variable as split delimiter

When you interpolate variables into regexes, they can contain regex metacharacters. For instance, $foo = '(?:bar|baz)'; /$foo/ matches bar or baz, not the literal "bar|baz". They can also escape those metacharacters: $foo = '(?:bar\|baz)'; /$foo/ matches the literal "bar|baz", not either bar or baz.

Your problem is your line: $delimiter = "\|"; Because you are using a double-quoted string that does it's own \-escaping, this sets $delimiter to just "|". Then using it in a regex as /$delimiter/ becomes /|/ (match nothing or nothing) which matches between every character, so you get "1", ".", "1", etc. from your split.

To set $delimiter properly to \|, use $delimiter = "\\|"; or $delimiter = '\|';

Replies are listed 'Best First'.
Re^2: Variable as split delimiter
by punch_card_don (Curate) on Mar 26, 2008 at 15:59 UTC
    Yep, that did it. That pesky double vs. single quote thing. Thanks.