in reply to Splitting the record using the delimiter

Above you told it to split on pipes. And what I get when I run it is "Hello\" which is split on pipes.

Are you trying to split on pipes except when preceded by a backslash? If so:

#!/usr/bin/perl use strict; my $id = 'Hi|Hello\|Sir'; my @code = split(/[^\\]\|/,$id); print $code[1]."\n";

Note: That since this now splits on a character followed by a pipe that $code[0] would be "H" and not "Hi". The short answer is you are looking for split to have a variable delimiter in this case. A pipe sometimes and no pipe at other times.

--
“For the Present is the point at which time touches eternity.” - CS Lewis

Replies are listed 'Best First'.
Re^2: Splitting the record using the delimiter
by graff (Chancellor) on Sep 30, 2015 at 23:30 UTC
    This is a case for a negative look-behind assertion:
    #!/usr/bin/perl use strict; my $id = 'Hi|Hello\|Sir'; my @code = split(/(?<!\\)\|/,$id); print $code[1]."\n";
    UPDATE: Sorry, I should have realized that I just repeated what kcott said in the previous reply.