in reply to Fast file parsing

I don't know enough about printing setups to see if the information could be obtained elsewhere, so let's see if we can speed up the parsing.

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:

unless ($pagestate && $pagesize && defined($title)) { # your tests }
That way you skip almost half the checks for most of the file.

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

if (/^%%/) { # your checks }
Thus skipping all those lines which aren't PS comments, and thus can't contain any data of interest to your script.

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

last if (defined($doctitle) && $copies && $pagesize && $pagestate);
With that, the code will stop reading the file as soon as it has all the data it needs.