in reply to Stripping Comments from Source

If you're skiled with Perl, any reason why you can't write a script (a Perl script, of course) to use a regex to strip out comments from your other Perl script?

That's beside the points that were mentioned above, of course, but why would you bother putting comments in the script in the first place? Why are comments a problem in "compiled" code? How is your Perl going to be compiled within .NET?

If this is something that you plan on doing more than a couple times (stripping comments out of a Perl script), I recommend a commentstrip.pl script that you can run on anything and everything that ends in .pl.

Replies are listed 'Best First'.
Re^2: Stripping Comments from Source
by LanX (Saint) on May 12, 2010 at 12:37 UTC
    If you're skiled with Perl, any reason why you can't write a script (a Perl script, of course) to use a regex to strip out comments from your other Perl script?

    It's not trivial to parse Perl even for a skilled programmer!

    e.g. regarding comments, you have to handle # delimiters and # in strings

    $a="/#/"; $a=~ s#/##g;

    (update) and these are only simple cases, even perltidy and PPI can fail in pathological cases. For a detailed discussion search for perl static parsing!

    Cheers Rolf

      Not to mention my own favorite syntax-highlighting-editor-confusers  $#array (highest index of @array) and the  $# special variable!

        seriously ... which editors?

        I somehow remember emacs having problems with s### 10 years ago with a then antique perl-mode...

        Cheers Rolf

      # FIXME Why doesn't this change behaviour when I compile it? print <<'END_TEXT'; Just stripping the remaining chars starting with # will not work END_TEXT