encapsulate the getting of stuff in a sub

This commit is contained in:
Yanick Champoux 2023-08-26 10:24:39 -04:00
parent 109ba04c35
commit 0c3f6949fa

View File

@ -7,12 +7,17 @@ use List::Util qw(sum);
use Text::SimpleTable::AutoWidth; use Text::SimpleTable::AutoWidth;
use WWW::Mechanize (); use WWW::Mechanize ();
sub get_mersenne_results() {
# log in to Mersenne.org and get results for the last year # log in to Mersenne.org and get results for the last year
# excluding everything but PHP and DD results # excluding everything but PHP and DD results
my $mech = WWW::Mechanize->new();
my $mech = WWW::Mechanize->new;
my $url = my $url =
'https://www.mersenne.org/results/?extf=1&exp1=1&execm=1&excert=1&exp_lo=2&exp_hi=&limit=10000'; 'https://www.mersenne.org/results/?extf=1&exp1=1&execm=1&excert=1&exp_lo=2&exp_hi=&limit=10000';
$mech->get($url); $mech->get($url);
$mech->submit_form( $mech->submit_form(
form_number => 1, form_number => 1,
fields => { fields => {
@ -21,15 +26,22 @@ $mech->submit_form(
} ); } );
# load the results into a table object # load the results into a table object
my $html_string = $mech->content(); my $html_string = $mech->content;
$html_string =~ s/\n//g; $html_string =~ s/\n//g;
my $te = HTML::TableExtract->new( depth => 0, count => 2 ); my $te = HTML::TableExtract->new( depth => 0, count => 2 );
$te->parse($html_string); $te->parse($html_string);
return $te->first_table_found;
}
my $ts = get_mersenne_results();
# group GHZ Days results by computer, compute GHZ Days per Day (GHZ Days / Days) # group GHZ Days results by computer, compute GHZ Days per Day (GHZ Days / Days)
my $list; my $list;
my $ts = $te->first_table_found();
foreach my $row ( $ts->rows ) { foreach my $row ( $ts->rows ) {
foreach my $cell ($row) { foreach my $cell ($row) {
my $machine = @$cell[0]; my $machine = @$cell[0];