Er... OK, but this looks and functions like what I had before. How do I incorporate multiple PRESERVE tags? For example, I need to s/\s+/ /g everywhere except between MARKA and MARKB, between STARTPRESERVE and STOPPRESERVE, and between YETANOTHERMARKER and YETANOTHERMARKEREND.
I can't loop through an array of regexes because they'd just cancel eachother out and do the s/\s+/ /g everywhere. I think I need a single regex, or perhaps a pulling appart of the string into an array split by the various markers, then each element analysed. What do you think is the best approach?
## START PSEUDO-CODE
my $string = $big_string_from_my_original_example;
my @array_of_stuff = split
/\b(?:STARTPRESERVE)|(?:STOPPRESERVE)\b|
\b(?:MARKA)|(?:MARKB)\b/, $string);
foreach (@array_of_stuff) {
if (&check_for_marker) {
push @new_array, $_;
next;
}
s/\s+/ /g;
push @new_array, $_;
}
$string = join '', @new_array;
## END PSEUDO-CODE
Oh, and I actually do need to remove line breaks but keep the markers in place. And although it's theoretically possible, I highly doubt any markers will ever be nested. (If they are, it's due to user error.)
gryphon
code('Perl') || die;
|