in reply to Re: How to test if a file is gzipped or not
in thread How to test if a file is gzipped or not

Testing for a file type is called "magic" in linux/unix, hence jwkrahn above mentions the magic file that facilitates translating file signatures to file types.

In a linux/unix you may test with the file command: file $fileyouwanttotest

CPAN has File::MimeInfo (and also File::MimeInfo:Magic, but the name is a bit misleading)
and it works like this:

use File::MimeInfo; my $mime_type = mimetype('perl-5.38.0.tar.gz'); print("$mime_type\n");

Cheers, Sören

Créateur des bugs mobiles - let loose once, run everywhere.
(hooked on the Perl Programming language)

Replies are listed 'Best First'.
Re^3: How to test if a file is gzipped or not
by choroba (Cardinal) on Jun 18, 2024 at 08:19 UTC
    There's also File::MMagic and File::Type, and many more.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]