in reply to Re: Removing Comments
in thread Removing Comments
If it starts with #!, leave it alone. If the line starts with a #, its a comment so delete it. If you find a # elsewhere, and is preceded by a ; (possibly with whitespace in between), hack off the end of the line. That should take care of 99% of your problems.This doesn't even begin to solve the problem. That won't handle this very legal example:
And it gets worse, much worse. I didn't even mention the backslash escape problems.#!perl -w use strict; # Always! # Call method foo like this: # my @results = foo( $arg1, \%hash ); # foo in array context sub foo { my ( $arg, $hashref ) @_; $arg =~ m/some regex # with true embedded comments on multiple lines/x; $arg =~ m/some regex with a # sign in it./; $arg =~ m/some regex with a ; # combo in it./; my $result1 = "a string with; # in it"; my $result2 = q; # nasty!;; # this comment has ' ' as the first char. return ( $result1, $result2 ) # no semi-colon! }
|
|---|