in reply to split unless escaped
As far as I can see the following works in all cases
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!"#!/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"};
|
|---|