in reply to split on unescaped delimiters
my @array = split /(?<!\\),/, $string;
It looks like your code is using a colon as the delimiter. This solution can be easily adapted to whatever delimiter or escape sequence you desire.
For more elaborate things, like balanced quotes, you're better off going to a Text::Balanced module, or maybe the DBD::CSV module.
Update: To answer the escaped escape problem that you've mentioned, you could resort to alternation within the split:
my @array = split/(?:\\\\,)|(?:(?<!\\),)/, $string;
You really end up with some ugly leaning toothpicks!
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: split on unescaped delimiters
by bsb (Priest) on Jan 08, 2004 at 09:43 UTC | |
|
Re: Re: split on unescaped delimiters
by bsb (Priest) on Jan 08, 2004 at 10:11 UTC |