So, there are some errors that would really stop the whole process, and others that only interfere with a particular file. Deal with the former before you start looping over files (die if any of them happen), and then deal with the latter inside the loop (and just warn about each one that happens).

Based on the OP code, something like this would be one way to go:

#!/usr/bin/perl -w use strict; use CAM::PDF; use CAM::PDF::PageText; use File::Spec::Functions; use File::Find::Rule; ## ... steps 1 and 2 as per OP code ... my $outputDir = 'F:/project_italia/firm_text'; ( -d $outputDir and -w _ ) or die "Output directory $outputDir not found or not writable\n"; open(LIST, ">>", 'F:/project_italia/firmList_pdf.txt' ) or die "Can't open destination.fil $!"; foreach (@allDir) { ... foreach (@filings) { my $fileName=$_; my $pdf = CAM::PDF->new($_) or do { warn "PDF->new failed on $_\n"; next; }; ... # open output text file (NB: ">>" appends, creates if necessar +y) open(DEST, ">>", "$outputDir/$textName[4].txt" ) or do { warn "Unable to append to $outputDir/$textName[4].txt: $!\ +n "; next; }; ...
It looks like you're on the right track with handling problems inside the page loop. Just tweak the layout of the warning messages to suit your taste -- that is, think about tailoring the warnings to make them easy to count, search, summarize, etc.

In reply to Re: Help with error handling by graff
in thread Help with error handling by eversuhoshin

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.