pvaldes has asked for the wisdom of the Perl Monks concerning the following question:
As everybody surely knows, the "file" command in bash prints info about the type of a file. (i.e file flower.jpg will show that this is a jpeg image)
I'm trying to achieve the same in a perl script. Thus I wrote something like this:
use strict; use File::Type; my $infile = "flower.jpg"; my $ft = File::Type->new(); my $type1 = $ft->checktype_filename($infile); my $type2 = $ft->mime_type($infile); print "$type1\n"; print "$type2\n"; print `file $infile`;
and my proto-script returns
image/jpeg image/jpeg flower.jpg: JPEG image data, JFIF standard 1.01
Thus we have a clear winner, the File::Type module, although not bad, is clearly less accurate that file. And that's the question: żDo you know any way/module/function integrated with perl to obtain the same amount of info about a file? or I need to use system here to call directly the file command?. The big nuisance here is that if you search for file + perl in google you obtain millions of unrelated results
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: file command replacement (showing the type of a file with perl)
by halfcountplus (Hermit) on Apr 17, 2012 at 12:41 UTC | |
|
Re: file command replacement (showing the type of a file with perl)
by Corion (Patriarch) on Apr 17, 2012 at 12:44 UTC | |
|
Re: file command replacement (showing the type of a file with perl)
by zwon (Abbot) on Apr 17, 2012 at 13:26 UTC | |
|
Re: file command replacement (showing the type of a file with perl)
by pvaldes (Chaplain) on Apr 17, 2012 at 14:04 UTC |