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

Hello. I'm writing a program that records the names of 25000+ users who place pretend bets at a fantasy sports website. I have already written a program that successful extracted all of their names. I then saved this to a file.

Then, to access each player's record, my program begins by setting up an array with an entry for each of the players. By typing in www.blablabla.combla?(PLAYERSNAME) I can get more detailed information about that player. Depending on what sports the player has placed bets on (there are 11 including a record for ALL sports), there will be a link if he has placed bets on those sports. I initially skim the general page to find out what sports he played, then I create an array that captures each sport. THen I proceed to get detailed records for each sport by creating an array of the sports he has played.

My program then loops through the @sports array that contains the sports they've played. Unfortunately, sometimes my program simply does not extract values for a whole loop of the array. I think my regexps are okay, because I can ALWAYS rerun the program from the failed point and successfully and accurately capture values for that iteration. Below is the code (any other recommendations as to better programming design are welcome

$browser = LWP::UserAgent->new(); $browser->agent("Mozilla/4.76 [en] (Win98; U)"); @sports= qw(ALL); open PLAYERS, "players.txt" or die; sub urldefine { + $url= URI-> new(''); + $url->query_form( 'Member' => $_[0], 'Sport' => "$_[1]",); } while (<PLAYERS>) { chomp $_; push (@plyrs, $_); } open DUMP, ">dump.txt" or die; open STATS2, ">>stats2.txt" or die; for ($i=17022; $i <= 19000; $i+=1) { @sports=(); @urlfeed = ($plyrs[$i], "all"); urldefine @urlfeed; $page=get("$url"); for my $a (split "&Spo", $page) { if ($a =~ /rt=(\w*)"/g) { push (@sports, $1); } } for ($j=0; $j <= $#sports; $j+=1) { print "."; @urlfeed = ($plyrs[$i], $sports[$j]); urldefine @urlfeed; $page= get("$url"); print STATS2 "Player\t", "Sport\t", "Season\t", "BetType\t +"; print STATS2 "Record\t", "Wins\t", "Losses\t", "Ties\t", " +Percent\t"; print STATS2 "Units\t", "Rank\t", "TotalRank\n"; for my $a (split "/td>", $page) { if ($a =~ /al">([AC]\w{2})/m) { $year="$1"} if ($a =~ /al">(\d{4})/m) { $year="$1"} if ($a =~ /"2">([AO].*?)</m) { print STATS2 $plyrs[$i], "\t", $sports[$j], "\ +t", $year. "\t", $1. "\t"; } if ($a =~ /18%"><SMALL>([^<].*?)</m) { print STATS2 $1, "\t"; if ($1 =~ /(\d+)-(\d+)-(\d+)/m) {print STATS2 +$1, "\t", $2, "\t", $3, "\t"} if ($1 eq "N/A") {print STATS2 $1, "\n"} } elsif ($a =~ /18%"><SMALL>.*?>(\d*)\s\w{2}\s(\ +d*)/m){ print STATS2 $1, "\t", $2, "\n"; } } } print "Finished Player #", $i+1,": ", $plyrs[$i], "\n"; }

20040824 Janitored by Corion: Added code tags