Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: check *.tmp wether it's a zip or not

by fglock (Vicar)
on Nov 26, 2004 at 13:29 UTC ( [id://410575]=note: print w/replies, xml ) Need Help??


in reply to Re: check *.tmp wether it's a zip or not
in thread check *.tmp wether it's a zip or not

Maybe the error was a warning, not a die:

$ perl -e ' eval { warn "xxx" } ' xxx at -e line 1. $ perl -e ' eval { die "xxx" } ' $

Replies are listed 'Best First'.
Re^3: check *.tmp wether it's a zip or not
by radiantmatrix (Parson) on Nov 26, 2004 at 15:18 UTC

    In which case, one might consider a local $SIG{__WARN__} handler:

    sub is_zip { #Load the file local $SIG{__WARN__} = sub { goto CONTINUE }; $status = $zip->read($file); CONTINUE: #Check $status }

    The code above is bad (it's an idea only), but the basic idea is to have a __WARN__ handler that supresses printing of the error and then branches to a goto tag outside itself, which keeps the default handler from being called.

    However, using mime-magic to determine the file type is probably better.

    #Read data into $file if ($file =~ m/^\x50\x4B\x03\x04/) { #Parse as ZIP file } else { #Parse as something else }

    Or automate that type of task with the previously-mentioned File::Type module.


    radiantmatrix
    require General::Disclaimer;
    Perl is

Re^3: check *.tmp wether it's a zip or not
by guha (Priest) on Nov 26, 2004 at 15:34 UTC
    perl -e "{ local $SIG{__WARN__} = sub { die @_;};eval {warn 'xxx'}; pr +int 'a:'. $@}" __OUTPUT__ a:xxx at -e line 1.

    That is check $@ for success.

    If you only check the signature, which is what my quick check into File::Type confirmed that it is doing, there is a risk even if it is remote that another binary file could start with these magic bytes.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://410575]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (8)
As of 2024-04-18 11:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found