in reply to Support for hash comments on a line

Note: untested code follows

If you know that #s won't appear in your data, you can write:

$line =~ s/^([^#]*)#.*$/$1/;

If #s can appear in quoted strings, life gets a little more complex:

$line =~ s/^ ( # grab this stuff in $1 ( [^#"]* # prefix of non-#s, non-"s (\" # start of string [^\"]* # content of string \")? # end of string [^#"]* # suffix )* # grab many prefix-string-suffixes ) \# # start of comment .* $ /$1/x;

(At this point, you may be better off using one of the Text modules, and if the input's really hairy, Parse::RecDescent.)

Update: Er, that second regex is s/.../$1/x;, not s/.../x;. Doh!

--
:wq