I read a file into an array using
@file=<FILE>.
Problem is I have to parse the data in the file excluding C-Style comments.
They may be only one line long:
/* this is a comment /*
or multiple lines:
/*
these 3 lines are comments
*/
I'm currently using the following code to process the file:
open (FILE,"file");
@file=<FILE>;
close(FILE);
for ($i=0; $i<=$#file; $i++) {
# Here I'm trying to catch the comments and ignore them
if ($file[$i]=~/\/\*/) { # If comment is found ...
while ($file[$i]!~/\*\//) { $i++; } # Check lines till finding end o
+f comment
next;
}
... processing data ...
}
My problem is that /\/\*/ doesn't match "/*". (without quotes)
I have also tried /\/\042/ which doesn't match, too.
Does anyone have an idea to solve this problem?
Thanks in advance.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.