LWP problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Travis

    LWP problems

    This is an example of LWP that I found on one of the perl docs pages.
    use LWP 5.64; this line is causing an external error.

    Does that mean I don't have LWP on my server or is something else wrong?

    Let me know if this works for you.
    #############
    use strict;
    use warnings;
    use LWP 5.64;
    my $browser = LWP::UserAgent->new;

    my $word = 'tarragon';

    my $url = 'http://www.altavista.c om/sites/search/web';
    my $response = $browser->post( $url,
    [ 'q' => $word, # the Altavista query string
    'pg' => 'q', 'avkw' => 'tgz', 'kl' => 'XX',
    ]
    );
    die "$url error: ", $response->status_line
    unless $response->is_success;
    die "Weird content type at $url -- ", $response->content_type
    unless $response->content_type eq 'text/html';

    if( $response->content =~ m{AltaVista found ([0-9,]+) results} ) {
    # The substring will be like "AltaVista found 2,345 results"
    print "$word: $1\n";
    } else {
    print "Couldn't find the match-string in the response\n";
    }
    ############### #


Working...