Hello all
I'm working on a print quota script that parses through a file to be printed to grab page numbers, paper size, and some others. My method works fine on jobs of small size, but takes forever on larger jobs. Is there a faster way to parse through a 60+ MB file? My method is thus:
open FILE, "$opt{d}/dfA$opt{j}$opt{h}" || die "cannot open $op +t{d}/dfA$opt{j}$opt{h}: $!\n"; while (<FILE>){ + + # Duplex or no... $pagestate = "Duplex" if (/^%%.* \*Duplex Duplex.*/ || /^[ +&l1S/ig || /^[&l2S/ig || /DUPLEX=ON/g); $pagestate = "Simplex" if (/^%%.* \*Duplex None.*/ || /^[& +l1S/ig || /DUPLEX=OFF/g); + + # Page Size $pagesize = "Letter" if (/^%%.* Letter/ || /^[&l2A/ig || / +PAPER=LETTER/g); $pagesize = "Legal" if (/^%%.* Legal/ || /^[L3A/ig || /PAP +ER=LEGAL/g); $pagesize = "Tabloid" if (/^%%.* Tabloid/ || /^[&l2000A/ig + || /PAPER=LEDGER/g); + + # Number of Pages # # Possible postscript flags are: # %%Pages: # # %%Page: # #^M # (%%[Page: #]%%) = ^M $pages = $1 if (/^\(?%%Page\w?: \d+? ?(\d+).*?/); + + # Number of copies $copies = $1 if (/^%%.* numcopies (\d+).*?/i); $copies = $1 if (/.*QTY=(\d+).*?/); + + # Document Title $doctitle = $1 if (/^%%Title: (.*)$/); chomp $doctitle; } close FILE;
The above grabs postscript and pcl flags for me, but it can be dirt slow. Anyone have any suggestions?

Thanks much!
Louie

In reply to Fast file parsing by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.