perl - Splitting the record using the delimiter -
i splitting record using delimiter '|'. encounter scenario pipe symbol(delimiter) preceded escape sequence,in case pipe symbol couldn't consider delimiter. how resolve using split? posted below sample piece of code
#!/usr/bin/perl use strict; $id = 'hi|hello\|sir'; @code = split(/\|/,$id); print $code[1]."\n";
the expected output above program "hello\|sir" actual output "**hello**".how handle delimiter preceded escape sequence using split.
thank you
you can't use split
, text::csv_xs
can parse format.
use text::csv_xs qw( ); $parser = text::csv_xs->new({ sep_char => '|', escape_char => '\\', quote_char => undef, auto_diag => 2, binary => 1, }); $parser->parse('hi|hello\|sir'); @fields = $parser->fields(); print("$fields[1]\n"); # hello|sir
Comments
Post a Comment