/ Published in: Perl
This Perl snippet shows how to separate quoted parts from a text in order to process quoted and unquoted parts separately. For example, you could expand variables or wildcards only in the unquoted part. Then the different processed parts are put together again.
That a marker character "\x01" is used to mark the position of the quoted passages is a bit ugly, but on the other hand the single line of code putting the text together again is very elegant and shows off what Perl can do!
That a marker character "\x01" is used to mark the position of the quoted passages is a bit ugly, but on the other hand the single line of code putting the text together again is very elegant and shows off what Perl can do!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
my @quoted; while( $text =~ s/('[^']*'|"[^"]*")/\x01/ ) { my $q= $1; # process quoted passages # ... } # process unquoted $text # ... $text =~ s/\x01/shift @quoted/eg;