http://qs1969.pair.com?node_id=268254


in reply to Bad Regex

You should try Regexp::Common::comment for common regexes that match comments. It will probably be better than rolling your own.

As for the line count, you can simply keep a counter as you go through the lines of the file. So, set a variable outside of your foreach loop and increment each time to get the new line number.

Replies are listed 'Best First'.
Re: Bad Regex
by Abigail-II (Bishop) on Jun 24, 2003 at 02:39 UTC
    Eh, no, not really. The OP seems to want to find comments inside a program. Regexp::Common just has regular expressions for comments - for Perl comments, it would find any text starting with a pound sign, and ending with the next newline. It's not a full language parser, something you really need if you want to find comments inside Perl programs. You might be able to get away skipping over anything inside quotes in a C or Java program, but that isn't true for Perl. You really need to parse (or be Damian).

    Abigail