sarvan has asked for the wisdom of the Perl Monks concerning the following question:
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using content-type for judgement
by moritz (Cardinal) on Jun 22, 2011 at 09:46 UTC | |
|
Re: using content-type for judgement
by planetscape (Chancellor) on Jun 22, 2011 at 11:35 UTC | |
|
Re: using content-type for judgement
by Utilitarian (Vicar) on Jun 22, 2011 at 12:26 UTC |