kpiti has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I need to split | delimeted line but with escaping potential \| strings. I'm playing with Text::Balanced but I'm not getting the right results.
Say I have a line like
1|str|foo\|bar|goo|2323
I need it to be split into the following fields:
1,str,foo\|bar,goo,2323
Any hints on the right (or smart, or both :) way to do this?
1|str|foo\|bar|goo|2323
I need it to be split into the following fields:
1,str,foo\|bar,goo,2323
The code:
will returnuse Data::Dumper; use Text::Balanced qw/extract_multiple extract_delimited/; $x=q[1|str|foo\|bar|goo|2323]; @a=extract_multiple($x, [sub {extract_delimited($_[0],qq{\|} )}], undef, 0); print Dumper(@a);
which is way wrong. And plain split will split on \| as well as plain |..$VAR1 = '1'; $VAR2 = '|str|'; $VAR3 = 'foo\\'; $VAR4 = '|bar|'; $VAR5 = 'goo|2323';
Any hints on the right (or smart, or both :) way to do this?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Trouble splitting pipe delimited
by Tanktalus (Canon) on Nov 05, 2012 at 04:40 UTC | |
by BillKSmith (Monsignor) on Nov 05, 2012 at 13:39 UTC | |
Re: Trouble splitting pipe delimited
by hbm (Hermit) on Nov 05, 2012 at 00:42 UTC | |
Re: Trouble splitting pipe delimited
by Anonymous Monk on Nov 05, 2012 at 01:09 UTC | |
Re: Trouble splitting pipe delimited
by BillKSmith (Monsignor) on Nov 05, 2012 at 02:41 UTC | |
Re: Trouble splitting pipe delimited
by kpiti (Novice) on Nov 05, 2012 at 08:14 UTC |
Back to
Seekers of Perl Wisdom