in reply to Help with error handling

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.

Replies are listed 'Best First'.
Re^2: Help with error handling
by eversuhoshin (Sexton) on Mar 20, 2011 at 02:33 UTC
    Thank you so much for your help graff :)