in reply to determine file type from data read from filehandle
You should never trust the file extension even if it's there. You can try File::Type or File::MMagic. I would probably just do something like (first-draft logic, untested)–
if ( "ok" eq eval { process_upload_as_excel($upload); "ok" } ) { # Do stuff, report success. } elsif ( $@ ) { my $first_err = $@; if ( "ok" eq eval { process_upload_as_cvs($upload); "ok" } ) { # Do stuff, report success. } else { die "Couldn't process as Excel or CVS..."; # Include $first_err and (new one) $@. Or don't. # I'm a code comment, not a cop. } } else { die "Unknown failure!"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: determine file type from data read from filehandle
by Eily (Monsignor) on Aug 07, 2018 at 16:42 UTC | |
by Your Mother (Archbishop) on Aug 07, 2018 at 17:34 UTC |