Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I'm trying to pull some statistics off a Yahoo page using LWP::Simple's get method. I noticed that my script would sometimes seem to hang inconsistently, so I stripped down the program to see if I could identify the problem.

I think get is hanging somewhere, but I don't understand why. I read a few other posts here, but wasn't able to find any advice on how to work around the problem. I don't think it's a timeout issue, because the program isn't running the "or die..." code.

Here's the stripped down script:

use strict; use LWP::Simple; my $leagueURL = ',RW +,LW,D'; my $data = get $leagueURL || die "Couldn't get $leagueURL"; while ( $data =~ m|<a href="/nhl/players/(\d+)">|gs ) { my $id = $1; my @stats = ($id); print STDERR "Getting player $id\n"; push( @stats, &getCareer($id) ); push( @stats, &getSplits($id) ); print STDOUT "@stats\n"; sleep(15); } sub getCareer { my ($id) = @_; my $url = "$id/career"; my $data = get $url || die "Couldn't get $url"; return ("gotCareer"); } sub getSplits { my ($id) = @_; my @s = (); my $url = "$id/splits?year=care +er"; my $data = get $url || die "Couldn't get $url"; return ("gotSplits"); }

I've run the stripped code four times now. The first time, it went through the while loop 7 times. Then 4, 2, and 6. In the current run, it's been working on the same iteration for the past twenty minutes.

I would expect if the request was timing out, that I'd be seeing the "Couldn't get $url." message, but that's no happening. Am I doing something wrong? Thank you.

Update: Changed $leagueURL to refer to real page instead of local file.

In reply to LWP::Simple Seems to Hang on get by svsingh

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2021-06-15 16:34 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (73 votes). Check out past polls.