Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

LWP:UserAgent usage

by sarvan (Sexton)
on Jun 22, 2011 at 04:26 UTC ( #910850=perlquestion: print w/replies, xml ) Need Help??

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

Hi there,

Thanks for the help in getting to know the what the url points to..

As suggested, with the help of LWP::UserAgent i now got the content type the pages points to..

use LWP::UserAgent; my $url = "http://de.arxiv.org/pdf/1106.3541"; print LWP::UserAgent->new->head($url)->headers->content_type()
The above code is what the suggestion i got and worked..

Now my question is, the 3rd line in the code prints the content-type of the given url. How do i access the values of content_type(). If i want to access it.. I mean i want to use that as a input for another if condition..

Any suggestion

Replies are listed 'Best First'.
Re: LWP:UserAgent usage
by Tanktalus (Canon) on Jun 22, 2011 at 04:47 UTC

    This isn't merely LWP::UserAgent usage. This is basic Perl syntax. Don't get me wrong - that's still perfectly on-topic for this site (I did approve the node after all), but let's get you the help where you're at: introduction to perl. Perhaps perlintro might help.

    What you probably want to do is capture every stage of that long 3rd line in separate variables so you can reuse them later.

    my $ua = LWP::UserAgent->new(); my $response = $ua->head($url); #HTTP::Response type return my $headers = $response->headers(); # HTTP::Headers type return my $content_type = $headers->content_type(); # string
    Now you have everything separated out. You can do whatever you want with them, without re-fetching the headers.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://910850]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2023-09-25 09:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?