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

Hello guys, I was reading a code, and a do not understand this:

my $url=<STDIN>; my $req=HTTP::Request->new(GET=>$url); my $ua=LWP::UserAgent->new(); $ua->timeout(15); my $response=$ua->request($req);

What this make? Please, can you explain me? And what is the difference of use this code to use:

#!/usr/bin/perl use LWP::Simple; my $url=<STDIN>; my $resul=get $url;

Tks.

Replies are listed 'Best First'.
Re: HTTP: :REQUEST
by kcott (Archbishop) on Jan 25, 2014 at 23:43 UTC

    G'day meanroc,

    I don't know which part of that code you "do not understand".

    The documentation for HTTP::Request and LWP::UserAgent have details.

    The first line reads input; the next two lines have constructors; the fourth line sets a timeout: these seem very straightforward but please specify if any of those are where your problem lies.

    The fifth line returns a response object. Perhaps this is where you're having difficulties. The two links above discuss this; HTTP::Response has details.

    Regarding the second code fragment, the documentation for LWP::Simple has details (as the name suggests, this provides a simplified interface). The get() method returns content (not a response object).

    -- Ken