cvs commit: perlfaq perlfaq6.pod
[email protected] (brian d foy) 25 Oct 2004 18:47:04 -0000
| Newsgroups | perl.cvs.perlfaq |
|---|---|
| Message-ID | <[email protected]> |
cvsuser 04/10/25 11:47:04
Modified: . perlfaq6.pod
Log:
* [perl #23131] warning from perl faq that strips C and C++ comments
* in regexes, add /e and test for defined-ness before using $2 in a
replacement.
Revision Changes Path
1.26 +4 -4 perlfaq/perlfaq6.pod
Index: perlfaq6.pod
===================================================================
RCS file: /cvs/public/perlfaq/perlfaq6.pod,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- perlfaq6.pod 22 Sep 2004 03:18:40 -0000 1.25
+++ perlfaq6.pod 25 Oct 2004 18:47:04 -0000 1.26
@@ -1,6 +1,6 @@
=head1 NAME
-perlfaq6 - Regular Expressions ($Revision: 1.25 $, $Date: 2004/09/22 03:18:40 $)
+perlfaq6 - Regular Expressions ($Revision: 1.26 $, $Date: 2004/10/25 18:47:04 $)
=head1 DESCRIPTION
@@ -354,7 +354,7 @@
$/ = undef;
$_ = <>;
- s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#$2#gs;
+ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse;
print;
This could, of course, be more legibly written with the C</x> modifier, adding
@@ -395,11 +395,11 @@
. ## Anything other char
[^/"'\\]* ## Chars which doesn't start a comment, string or escape
)
- }{$2}gxs;
+ }{defined $2 ? $2 : ""}gxse;
A slight modification also removes C++ comments:
- s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#$2#gs;
+ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse;
=head2 Can I use Perl regular expressions to match balanced text?