in reply to split unless escaped

I've looked at your solution, it works for a single pair of backslashes at the end of a line, but it doesn't work in the most general case i.e. any number of backslashes at the end of one of the strings to be split. An odd number of backslashes means that the ampersand is backslashed, this is accounted for. However when there are an even number of backslashes they will be reduced to a single pair.

As far as I can see the following works in all cases

#!/usr/bin/perl -w use strict; my @split; my $var; # the original string that I want to split my $tosplit = q(a=1&b=2\&3\&c=4\\\\\\\\\\\&d=5); # print out the string to confirm how many backslashes have been left # by the quote statement print $tosplit . "\n\n"; # Split the string on the ampersand my @temp = split /&/, $tosplit; # Rejoin any strings that should not have been split while ($_ = shift @temp) { $_ .= ("&" . shift @temp) and redo if /[^\\]\\(\\\\)*$/; push @split, $_; }; # print the array so we can see the results foreach $var (@split) {print "$var" . "\n"};
Baldrick, you wouldn't see a subtle plan if it painted itself purple and danced naked on top of a harpsichord, singing "Subtle plans are here again!"