I don't have any example files to see if my assumptions are sound, so I will try to make them explicit, and you can discard the advice that is rendered invalid by the incorrect ones.
First of all, I assume that the "global" data (duplex/simplex, pagesize, document title) only appears at the start of the file, and not somewhere in the middle.
So you could wrap those tests with:
That way you skip almost half the checks for most of the file.unless ($pagestate && $pagesize && defined($title)) { # your tests }
That leaves checks for number of pages, number of copies (oops, maybe that fits into the first section: the ones that only appear at the start).
Since everything (except the QTY=(\d+) match for the number of copies) starts with a postscript comment, you can wrap all those tests with
Thus skipping all those lines which aren't PS comments, and thus can't contain any data of interest to your script.if (/^%%/) { # your checks }
In the worst case, only the QTY=(\d+) check needs to look at all the lines of the file, and if that's a header notation, not even that.
Oh, and one more thing:Unless the last value for pages you find in the file is the applicable one, you might put
With that, the code will stop reading the file as soon as it has all the data it needs.last if (defined($doctitle) && $copies && $pagesize && $pagestate);
In reply to Re: Fast file parsing
by matija
in thread Fast file parsing
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |