agent00013 has asked for the wisdom of the Perl Monks concerning the following question:

$link = "http://www.something.com/picture.gif"; $link2 = "http://www.something.com/index.html"; $link3 = "http://www.something.com/something/script"; $link4 = "http://www.something.com/directory";
Given these fourlinks, how can I make my script recognize that one is an , one is HTML, one is a script, and one is a directory?

I don't want to use any regex for this (as I've already got some that work, but I'm looking for a simpler approach and it has difficulty working with the third and forth links. note: I don't control these links, only the script).

I know using LWP::Simple and it's head() function I can determine things like file size, etc. What module/function can I use to determine file type? (example: http/text - or whatever format is used)

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How do I determine file type based on web page response?
by chromatic (Archbishop) on Jun 22, 2001 at 22:56 UTC
    From the LWP::Simple manpage description of get(): You will not be able to examine the response code or response headers (like 'Content-Type') when you are accessing the web using this function.  If you need that information you should use the full OO interface (see the LWP::UserAgent manpage). Using LWP::UserAgent, you'll get back something that implements HTTP::Headers, so you can just call its content_type() method.