PERL before swine
October 19, 2009 11:23 AM
Subscribe
PERL filter: I'm a PERL ignoramus and trying to run a script from
Baseball Hacks to download a bunch of zipped files from retrosheet.org. I'm getting an error that says: URL must be absolute. I can't figure out how to make the url absolute, as each file's location is different and supplied by variable values. Any hints would be super appreciated. (Script is after the jump).
Here's the script- copied directly from the book- I only modified the date ranges and changed the non-html-friendly characters for the purposes of posting here:
use FileHandle;
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$baseurrl = "http://www.retrosheet.org/";
for ($year = 60; $year LESSTHAN= 92; $year++) {
foreach $league ("al", "nl") {
my $filename = '19' . $year . $league . '.zip';
my $url = $baseurl . '19' . $year . '/19' . $year . $league . '.zip';
my $req = HTTP::Request->new(GET =GREATERTHAN $url);
my $res = $ua-GREATERTHANrequest($req);
print STDERR "fetching $filename\n";
if ($res-GREATERTHANis_success) {
my $fh = new FileHandle "GREATERTHAN$filename";
if (defined $fh) {
print $fh $res->content;
$fh-GREATERTHANclose;
} else {
print STDERR "could not open $filename: $!\n";
}
}
else {
print STDERR $res->status_line, "\n";
}
}
}
posted by bluejayway to technology (8 comments total)
should probably be
(note the extra 'r' in 'url' in the original version).
posted by Godbert at 11:27 AM on October 19