Hi there,

My perl program gets input as returns a url(its a pdf searcher program). Once i get the url, i used LWP::useragent(head,content_type) to know the type of the content the url holds.

So far, i have got types like application/pdf,application/x-pdf,application/octent-stream,text/html,text/plain.

My question is i want to turn my program to print three kinds of print statements according to this return type of content-type

for e.g: if content-type of the url is "application/pdf" then print "file exist". or if content-type of the url is "text/html" then print "file exist but requires subscription" or simple "no matching found" if there is no url returned..

The problem now is, it only works for this two types of content. but when there are other kinds of contents returned it will not work..

foreach(@urls) { my $ua = LWP::UserAgent->new(); my $url = "$_"; my $response = $ua->head($url); #HTTP::Response type return my $headers = $response->headers(); # HTTP::Headers type return my $content_type =$headers->content_type(); # string print "$content_type\n"; } if($content_type eq 'application/pdf') { print "File Exists:\n $_"; } elsif($content_type eq 'text/html') { print "File Exists but requires subscription to access:\n"; } else{ print "No Matching found"; }

In reply to using content-type for judgement by sarvan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.