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; }
In reply to strip JS-comments by Skeeve
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |