I thought you said you needed to report some sort of statistic, too. ;^)What I have done is: read the file line by line skip empty line, comment line, muiltiline comment lines close file Is it enough?
The preference of whether or not to use a parser would depend on how simple or complex the input data is -- and how consistent or variable it is. Even if you don't need to worry about XML syntax errors (really? are you sure about that?), I would think that if you don't do some sort of sanity checking on the data, your statistics may turn out to be (ahem) inaccurate in ways you might not expect...
You should just check the docs for one or another XML parser module on CPAN to see whether it's suitable for you, and to see how to use it.
And... what is it exactly that you are trying to count? Lines? Elements? Tags? Text contained within tags? Depending on your goals, a parsing module could make things a lot easier in the long run.
If you know the data well, and it's fairly simple and consistent, and your output statistics seem reasonable, then you probably are doing well enough with your current approach; if it ain't broke, don't fix it. (But it's hard for me to say for sure, since you don't show any of your perl code, or any real data, and you don't say whether you're having any problem with it.)
In reply to Re: How to count lines of code for XML file?
by graff
in thread How to count lines of code for XML file?
by sachaer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |