#die 1; ###################### # File conversion: xls->txt ####################### local $SIG{ALRM} = sub { die("TIMED OUT") }; eval { alarm(10); #set our alarm # sleep 5; # with this sleep, the alarm works. But with the code below it doesn't... if ( $extension eq "xls") { my $infile = "../thissite/myuploads/$user/$systemname"; my $outfile = "../thissite/myuploads/$user/inventory.txt"; # Requesting extra modules: use Spreadsheet::ParseExcel; use Data::Dumper; # Openning the file dump open (DUMP, ">$outfile") || warn "Error opening file: $!\n"; select DUMP; # Excel parsing my $prev_index = -1; my $prev_row = 0; my $prev_col = 0; my $cell_handler = sub { my $workbook = $_[0]; my $sheet_index = $_[1]; my $row = $_[2]; my $col = $_[3]; my $cell = $_[4]; # Only process the first worksheet if ($sheet_index > 0) { $workbook->ParseAbort(1); return; } # Reset the col counter between rows $prev_col = 0 if $row != $prev_row; # Add tabs between fields and newlines between rows. Also pad # any missing rows or columns. # print "\n" for $prev_row +1 .. $row; print "\t" for $prev_col +1 .. $col; # Print the UNformatted value of the cell print $cell->{Val}; # Keep track of where we are $prev_row = $row; $prev_col = $col; }; my $parse_excel = new Spreadsheet::ParseExcel(CellHandler => $cell_handler, NotSetCell => 1); my $workbook = $parse_excel->Parse("$infile"); ############ ############ alarm(0); close DUMP; select STDOUT; } }; if ( $@ =~ /TIMED OUT/ ) { die "CONVERSION TIME EXCEEDED. FILE MAY BE CORRUPT!"; } #die 2; #### local $SIG{ALRM} = sub { die("TIMED OUT") }; eval { alarm(10); #set our alarm my $workbook = $parse_excel->Parse("$infile"); alarm(0); };