in reply to Handling escapes while splitting lines

mikecarlton,
I tend to use split when I am trying to split.
my $string = 'a\:b:c'; my ($key, $val) = split /(?<!\\):/, $string, 2; print "$key, $val\n";
Of course you then need to remove the escape characters from the resulting strings, but I left that as an excersise for the reader.

Cheers - L~R

Replies are listed 'Best First'.
Re^2: Handling escapes while splitting lines
by Eimi Metamorphoumai (Deacon) on Jan 19, 2005 at 02:05 UTC
    I don't think that will work correctly if the last character of the key is an escaped backslash. That is,
    my $string = 'a\\\\:b:c';
    The key should be 'a\' and the value 'b:c' (after removing escapes), but you'll end up with 'a\:b' and 'c'.
      Eimi Metamorphoumai,
      Right you are. This is one of those confessions I need to make. It frustrates me when people respond to my post without having read it closely enough to see that their reply is not applicable and yet I have done the same thing here. I completely missed the part about a double backslash being a literal backslash. I was thinking that the only thing that could be escaped was the colon. Thanks for correcting me and reminding me the importance of reading carefully.

      Cheers - L~R