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!
In reply to Re: Timeout for parsing corrupted excel files
by naikonta
in thread Timeout for parsing corrupted excel files
by Andre_br
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |