From 0c3f6949fa80aaae270f519465998ae68c6c35fe Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sat, 26 Aug 2023 10:24:39 -0400 Subject: [PATCH] encapsulate the getting of stuff in a sub --- script.pl | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/script.pl b/script.pl index ebb5177..46beb42 100644 --- a/script.pl +++ b/script.pl @@ -7,29 +7,41 @@ use List::Util qw(sum); use Text::SimpleTable::AutoWidth; use WWW::Mechanize (); -# log in to Mersenne.org and get results for the last year -# excluding everything but PHP and DD results -my $mech = WWW::Mechanize->new(); -my $url = - 'https://www.mersenne.org/results/?extf=1&exp1=1&execm=1&excert=1&exp_lo=2&exp_hi=&limit=10000'; -$mech->get($url); -$mech->submit_form( - form_number => 1, - fields => { - user_login => $ENV{'MERSENNE_USER'}, - user_password => $ENV{'MERSENNE_PASSWORD'}, - } ); +sub get_mersenne_results() { + # log in to Mersenne.org and get results for the last year + # excluding everything but PHP and DD results -# load the results into a table object -my $html_string = $mech->content(); -$html_string =~ s/\n//g; -my $te = HTML::TableExtract->new( depth => 0, count => 2 ); -$te->parse($html_string); + my $mech = WWW::Mechanize->new; + + my $url = + 'https://www.mersenne.org/results/?extf=1&exp1=1&execm=1&excert=1&exp_lo=2&exp_hi=&limit=10000'; + + $mech->get($url); + + $mech->submit_form( + form_number => 1, + fields => { + user_login => $ENV{'MERSENNE_USER'}, + user_password => $ENV{'MERSENNE_PASSWORD'}, + } ); + + # load the results into a table object + my $html_string = $mech->content; + + $html_string =~ s/\n//g; + + my $te = HTML::TableExtract->new( depth => 0, count => 2 ); + + $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) my $list; -my $ts = $te->first_table_found(); foreach my $row ( $ts->rows ) { foreach my $cell ($row) { my $machine = @$cell[0];