Perl module for 'file' command?

file, file-type, perl

Solution

If you know you'll be on a sane Unix, you can just make a system call to `file`.

If you need an independent implementation, there are several available on CPAN. Probably the closest to `file` is File::MMagic. This is its own implementation, so it will work on any system, but might not act exactly like `file`.

$ head test.pl
#!/usr/bin/env perl

use strict;
use warnings;

$ file test.pl
test.pl: a /usr/bin/env perl script text executable, ASCII text

$ perl -wlE 'use File::MMagic; $mm = File::MMagic->new; say $mm->checktype_filename(shift)' test.pl
x-system/x-unix;  executable /usr/bin/env script text

Problem

On a Linux system I can use the `file` command to detect the type of a file. Is there a `perl` module that encapsulates this command?

Original source