This FAQ is needlessly obscure, even with Fred Curtis's modifications.

Nobody needs a version which strips just C style comments. How about substituting the attached version which does both C and C++ style?

(The C spec requires /*...*/ to act as white space. DOS format text needs the \r.)

I am placing this code in the public domain.

I think the perl4 version of the code should be omitted, or moved to the end if you want to make the "perl5 with /x is more legible" point.

Bill Mann <[EMAIL PROTECTED]>

#!/usr/bin/perl -w

$/ = undef;                     # no line delimiter
$_ = <>;                        # read entire file

s! ((['"]) (?: \\. | .)*? \2) | # skip quoted strings
   /\* .*? \*/ |                # delete C comments
   // [^\n\r]*                  # delete C++ comments
 ! $1 || ' '                    # change comments to a single space
 !xseg;                         # ignore white space, treat as single line
                                # evaluate result, repeat globally
print;

Reply via email to