#!/usr/bin/perl

# apt-get install libfile-mmagic-perl
# This uses magic(5) to determine file type
use File::MMagic;

my $Magic = File::MMagic->new();
my $Name;
while($Name = shift @ARGV)
  {
  print "File \'$Name\' is " . $Magic->checktype_filename($Name) . "\n";
  }

# File types:
# ZIP = "application/x-zip"
# JAR = looks like ZIP
# RPM = "application/octet-stream" (ouch!)
# RAR = ???

###################################################
# Sample code: http://www.perladvent.org/2002/7th/
# #!/usr/bin/perl

# # turn on perl's safety features
# use strict;
# use warnings;

# # load the modules
# use File::MMagic;

# # new parser
# my $mm = File::MMagic->new();

# # open the dir
# opendir DIR, $ARGV[0]
#    or die "Couldn't open the directory '$ARGV[0]': $!";

# # work though the files in the dir
# my %files;
# while (my $file = readdir DIR)
# {
#   # skip it if it isn't just a normal file
#   next unless -f $file;

#   # get the mime type and other info
#   my $magic =  $mm->checktype_filename($file);

#   # delete anything after the mime type
#   $magic =~ s/ ;  # look for a the first semicolon
#                .* # and then anything up until
#                $  # the end of line
#                /;/x;

#   # add on that size to a hash
#   $files{ $magic } += -s $file;
# }
# closedir DIR;


