How can I ignore C comments when I process a C source file with Perl?
- by YoDar
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 the answer to How can I strip multiline C comments from a file using Perl?
$/ = 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?