Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Comment Stripper script for unix

by Zaxo (Archbishop)
on Jun 14, 2004 at 02:49 UTC ( #366391=note: print w/ replies, xml ) Need Help??


in reply to Comment Stripper script for unix

I tried applying this script to itself. That was to check if significant uses of '#' were handled properly. The results were, uhhh . . . unfortunate.

  1. It stripped the shebang line, which doesn't look exotic at all.
  2. It did
    -if ( $us eq "ee" ) { $comm = ';'; } else { $comm = '#'; } +if ( $us eq "ee" ) { $comm = ';'; } else { $comm = '
    leaving an unclosed quote in the code.
  3. It did
    - die(&pwarn($comm)) if $topline =~ /\#\!.*perl/i ; + die(&pwarn($comm)) if $topline =~ /\
    leaving an open regex match.
  4. It did
    - if ( $topline =~ /(\s+)\#\!/ ) { + if ( $topline =~ /(\s+)\
    to the same effect.

I think your e can only be applied in the simplest circumstances.

Don't feel too bad, the saying goes, "Only perl can parse Perl." To do this sort of thing properly really does require a parser.

After Compline,
Zaxo


Comment on Re: Comment Stripper script for unix
Select or Download Code
Re^2: Comment Stripper script for unix
by eserte (Deacon) on Jun 14, 2004 at 09:19 UTC
    Don't feel too bad, the saying goes, "Only perl can parse Perl." To do this sort of thing properly really does require a parser.
    ... or take a look at perltidy, which does a really good job on perl code formatting and also has a switch for stripping comments.
Re^2: Comment Stripper script for unix
by hsinclai (Deacon) on Jun 14, 2004 at 11:55 UTC
    Whoa - that's terrible - obviously I didn't test it with Perl scripts enough - I only used it with config files and shell scripts really - way too hasty ...

    This plain doesn't work and should be removed from the code catacombs - you all are too kind! Or maybe moved to the "don't let this happen to you" section?

    I didn't know Perltidy removed comments, so thanks for that eserte.





Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://366391]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (13)
As of 2014-07-28 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (202 votes), past polls