#!/usr/bin/perl use strict; use warnings; use LWP::Simple; ##################################################################### ### Set how many times to run, how long (in seconds) to wait between ### page hits, and how often to print an interim status report. my ($iterations, $nice, $status_print_interval) = (100, 5, 5); ##################################################################### my %quips; $SIG{INT} = sub{ print_results(\%quips); exit(0) }; my $loopcount = 0; print "Beginning PerlMonks Quip Gatherer...\n"; while($iterations > 0){ my $content = get('http://www.perlmonks.org'); die "Failed to load content!\n" unless defined($content); extract_quip(\%quips, \$content); $iterations--; $loopcount++; print "Found ", scalar keys %quips, " quip(s) so far, $iterations iteration(s) left...\n" if ($loopcount % $status_print_interval == 0); sleep($nice) if ($iterations); } print_results(\%quips); ##################################################################### ### SUBS ### ##################################################################### sub extract_quip{ my ($quips, $content) = @_; if ($$content =~ m!<td class="monkquip"[^>]+>(.*?)</td>!s){ my $data = $1; $data =~ s!\<[^>]*>!!sg; $data =~ s!\s{2,}!!sg; $quips->{$data}++; } } sub print_results{ my $quips = shift; print "\n********** RESULTS **********\n"; while (my ($key, $val) = each(%$quips)){ print "$val time(s): $key\n"; } }

In reply to PerlMonks Quips Gatherer by crashtest

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.