in reply to Timeout for parsing corrupted excel files
I can see two things in your code: a) warning on failed open. Instead, you should do some exception here because there's no point to continue if you can't open the file.use strict; use warnings; use Spreadsheet::ParseExcel; my $file = shift; my $excel; eval { local $SIG{ALRM} = sub { die "timeout\n" }; alarm(5); $excel = Spreadsheet::ParseExcel::Workbook->Parse($file); die "Can't parse $file\n" unless defined $excel; alarm(0); }; die $@ if $@; # contiune with $excel object
b) you need to check $@ in all possible cases, not just timeout, to capture other potential errors.open DUMP, ">filename" or die "Can't open: $!\n";
if ($@) { # something bad occures if ($@ =~ /TIME OUT/) { # do something regarding timeout } else { # do something with other reason, # such as failure on open } # stop here } # continue here
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Strange MS characters are the ones causing trouble at the parsing code
by Andre_br (Pilgrim) on May 09, 2007 at 18:48 UTC | |
by naikonta (Curate) on May 10, 2007 at 02:56 UTC | |
|
Re^2: Timeout corrupted excel files: MS characters freeze code
by Andre_br (Pilgrim) on May 09, 2007 at 18:52 UTC | |
by naikonta (Curate) on May 10, 2007 at 03:09 UTC |