I got parse times down from 90 seconds to 1-2 seconds on a 42MB test file. I appreciate the help a great deal.open FILE, "$ARGV[0]"; while (<FILE>){ if (/^%%EndSetup.*/){ $doctitle = "Unknown Document Title" unless defined($doctitle) +; $pagestate = "Simplex" unless defined($pagestate); $pagesize = "Letter" unless defined($pagesize); $copies = 1 unless defined($copies); } + + # Document Title unless (defined($doctitle)){ chomp ($doctitle = $1) if (/^%%Title: (.*)$/); } + + # Duplex or no... unless (defined($pagestate)){ $pagestate = "Duplex" if (/^%%.* \*Duplex Duplex.*/ || /^\[&l1 +S/i || /^\[&l2S/i || /DUPLEX=ON/); $pagestate = "Simplex" if (/^%%.* \*Duplex None.*/ || /^\[&l1S +/i || /DUPLEX=OFF/); } + + # Page Size unless (defined($pagesize)){ $pagesize = "Letter" if (/^%%.* Letter/ || /^\[&l2A/i || /PAPE +R=LETTER/); $pagesize = "Legal" if (/^%%.* Legal/ || /^\[L3A/i || /PAPER=L +EGAL/); $pagesize = "Tabloid" if (/^%%.* Tabloid/ || /^\[&l2000A/i || +/PAPER=LEDGER/); } + + # Number of copies unless (defined($copies)){ $copies = $1 if (/^%%.* numcopies (\d+).*/i || /.*QTY=(\d+).*/ +); } + + # Number of Pages unless (defined($pages)){ $pages = $1 if (/^%%Pages:\s+(\d+).*/); } } close FILE;
In reply to Re: Fast file parsing
by Anonymous Monk
in thread Fast file parsing
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |