in reply to Re: strip perl comment lines
in thread strip perl comment lines

Meanwhile, back at the ranch, there's a one-liner to be built around:
use Regexp::Common;
and
s/$RE{comment}{Perl}//;
if you want one.. Another Conway special.

Replies are listed 'Best First'.
Re: Re: Re: strip perl comment lines
by danger (Priest) on Mar 05, 2001 at 20:35 UTC

    On the off chance that you aren't merely kidding around and haven't looked at the module in question, I feel compelled to point out a couple of things. Not only does Regexp::Common's Perl comment matcher (which is essentially this re: /#[^\n]*\n/) suffer from the various problems listed previously, but your example use also doesn't come close to what epoptai was originally trying to do (which was to just strip lines beginning with optional whitespace and a # character, with the exception of the shebang line). Your example of:

    s/$RE{comment}{Perl}//;

    would delete *any* # character (comment or not) to the end of a line (including the newline character) and turn the following code:

    #!/usr/bin/perl -w use strict; $_ = "blah # blah"; s#blah #boog#gx; print;

    into:

    use strict; $_ = "blah s print;

    Which is useful only useful insofar as it demonstrates the problems inherent with simple attempts to strip Perl comments.