Thank you. That certainly makes sense. I feel though I should probably back up and clarify the root problem though.

I am working with a collection of PDF files and am using the pdftohtml.exe program to convert the PDF into an XML stream in order to extract text of interest with XML::Twig:

open (my $XML, "-|", "e:\\path\\to\\pdftohtml.exe -xml -zoom 1.4 -stdo +ut $PDF_FILE") or die "pdftohtml failed:\n$!\n$^E"; my $t = XML::Twig->new( twig_handlers => { '/pdf2html/pagetext[(@top >= 180 and @top <= 190) and (@left > += 100 and @left <= 111)]' => \&RouteTo, '/pdf2html/pagetext[(@top >= 215 and @top <= 225) and (@left > += 260 and @left <= 270)]' => \&InvoiceSort, '/pdf2html/page' => sub { $_[0]->purge; 1; }, # free memory af +ter every page }, comments => 'drop', # remove any comments empty_tags => 'normal',# empty tags = <tag/> ); $t->parse($XML); close $XML;

The problem is that if I fat-finger the open command (e.g. type "-zom" instead "-zoom" in the command arguments), or if "$PDF_FILE" could not be found, the program merrily continues on its way, unaware that $XML is undefined. I've been working around this by wrapping the "$t->parse" in an eval block to catch this, but I was wondering if there was a better way.


In reply to Re^2: Capturing errors from 3-arg pipe open in ActivePerl 5.020 by ateague
in thread [SOLVED] Capturing errors from 3-arg pipe open in ActivePerl 5.020 by ateague

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.