Perl Strip Comments with Regex Unique Request

Posted by YoDar on Stack Overflow See other posts from Stack Overflow or by YoDar
Published on 2010-04-14T08:01:05Z Indexed on 2010/04/14 8:02 UTC
Read the original article Hit count: 238

Filed under:

Hello,

I'm running a code that read files, do some parsing but need to ignore all comments. There are good explanations how to conduct it. like this link

$/ = undef;
$_ = <>;
s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse;
print;

My first problem is that after run this line $/ = undef; my code doesn't work properly. Actually, I don't know what it does. But if I could turn it back after ignoring all comments it will be helpful.

In general, What is the useful way to ignore all comments without changing the rest of the code ?

Thanks, YoDar

© Stack Overflow or respective owner

Related posts about perl