in reply to split function for | and \| delimiter
The most robust solution is probably to use Text::CSV, which can handle delimiters and escaped delimiters.
If you want to do it with a regex, you must split on a vertical bar that is not preceeded by a backslash.
Since both the vertical bar and the backslash are meta characters in regexes, you need to backslash-escape both:
my @chunks = split /(?<!\\)\|/, $yourstring;
See perlretut for more details.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: split function for | and \| delimiter
by xorl (Deacon) on May 25, 2012 at 18:52 UTC | |
|
Re^2: split function for | and \| delimiter
by darklord_999 (Acolyte) on May 25, 2012 at 19:16 UTC | |
by toolic (Bishop) on May 25, 2012 at 19:22 UTC | |
by darklord_999 (Acolyte) on May 25, 2012 at 19:30 UTC |