Sometimes you need a lightweight way of figuring out mime type. If you feel that you can do it by file extension this little snippet will work on most linux systems.
my %mime_type = (); open (MIME, "/etc/mime.types") || die "can't open mime.types:$!\n"; + while (<MIME>) { if (/^(\w\S+)\s+([\S\s]+)\n/) { my $mime = $1; my $tags = $2; while ( $tags =~ /\G(\w+)\s?/g ){ $mime_types{$1} = $mime; } } } close (MIME);

Replies are listed 'Best First'.
Re: Parsing /etc/mime.types into something usable
by Fletch (Bishop) on Nov 27, 2001 at 21:30 UTC

    Of course if LWP is installed there's always the LWP::MediaTypes module and its guess_media_type function.