use strict; use warnings; use MIME::Lite; use LWP::Simple; use Text::CSV; use HTML::TreeBuilder; # Fetch the "pages" my $content = get("http://perlmonks.org/?node_id=1173447"); die "Couldn't get it!" unless defined $content; # Parse pages and clean up content my $root = HTML::TreeBuilder->new_from_content($content); my ($page1, $page2) = map {$_->as_text()} $root->find_by_tag_name('pre'); s/\[download\]//g for $page1, $page2; s/\n\+//g for $page1, $page2; # Process page 1 my $csv = Text::CSV->new(); my %idData; open my $pg1In, '<', \$page1; while (my $row = $csv->getline($pg1In)) { s/^\s+|\s+$//g for @$row; $idData{$row->[1]}{size} = $row->[0]; $idData{$row->[1]}{name} = '-- missing --'; } close $pg1In; # Process page 2 $page2 =~ s/\b(?=\w+,)/\n/g; # Insert newlines in front of id codes open my $pg2In, '<', \$page2; while (my $row = $csv->getline($pg2In)) { next if !$row->[0]; # Skip blank lines s/^\s+|\s+$//g for @$row; $idData{$row->[0]}{name} = $row->[1]; $idData{$row->[0]}{size} //= '-- missing --'; } close $pg2In; # Generate output string my $output; for my $id (sort keys %idData) { $output .= "$id: $idData{$id}{name} size $idData{$id}{size}\n"; } # Build the email my $msg = MIME::Lite->new( From => 'me@myhost.com', To => 'you@yourhost.com', Cc => 'some@other.com, some@more.com', Subject => "Here's the data you wanted", Data => $output ); # and "send" it (just '$msg->send()' in the next line to really send it print $msg->as_string();