Skeeve has asked for the wisdom of the Perl Monks concerning the following question:
Here is what I gave him after discussing that he didn't use regexes in his JS programs (so no need to take car of // being somthing else than a comment).
Maybe someone more perlish than me likes to add his or her comments to it!?
#!perl use strict; my $qs =qr/'(?:[^']|\\')*'/; my $qqs=qr/"(?:[^"]|\\")*"/; my $ncs=qr<(?:[^'"/]|/[^/*])>; #' my $nocomment=qr/(?:$ncs|$qqs|$qs)*/; my $hit; while (<>) { # remove multiline /* comment if ($hit= s{^($nocomment)/\*(?:[^*]|\*[^/])*$}{$1}o ... s{^.*? +\*/}{}) { redo if $hit=~ /E0/i; $_="\n" if $hit>1; print; next; } # remove one-line /*...*/ comment 1 while s{^($nocomment)/\*.*?\*/}{$1}o; # remove // comment s{^($nocomment)//.*}{$1}o; print; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: strip JS-comments
by antirice (Priest) on Jun 10, 2003 at 18:43 UTC | |
by Skeeve (Parson) on Jun 11, 2003 at 05:43 UTC | |
|
Re: strip JS-comments
by allolex (Curate) on Jun 11, 2003 at 15:19 UTC | |
|
Re: strip JS-comments
by diotalevi (Canon) on Jun 10, 2003 at 13:40 UTC | |
by Skeeve (Parson) on Jun 10, 2003 at 13:51 UTC | |
by diotalevi (Canon) on Jun 10, 2003 at 13:56 UTC | |
by Skeeve (Parson) on Jun 10, 2003 at 14:02 UTC | |
by Jenda (Abbot) on Jun 10, 2003 at 15:14 UTC |