Small CGI program to return a random entry from the jargon file.

I started thinking about how I really should read stuff on that place more, so I whipped this together and am using it as my start page. You can currently test it at http://dogandpony.perlmonk.org/cgi-bin/jargon.pl.

#!/usr/bin/perl -w # Random jargon file redirect. # # Use it as your start page, or # as yet another funny link on # your home page... # # Stuff to do includes error handling # and possibly local mirroring. # But hey, it's a snippet, not production code... :) use strict; use LWP::Simple; use HTML::TokeParser; use CGI; # Everybodys fav object. my $q = CGI->new; # The chapters to choose from. my @chapters = (0, 'A'..'Z'); # Choose one. my $chosen = $chapters[ rand(@chapters) ]; # Get the index page for choen chapter: my $index_page = get( "http://www.tuxedo.org/~esr/jargon/html/-$chosen +-.html" ); # Another fav object: my $parser = HTML::TokeParser->new( \$index_page ); # List of pages under chosen chapter: my @href_list; # This is based on the current format of the jargon files # which should be unlikely to change though. while( $parser->get_tag( 'li' ) ) { # Get all links on that particular page. push @href_list, @{$parser->get_tag( 'a' )}[1]->{'href'}; } # And randomly choose one... my $href = $href_list[ rand(@href_list) ]; # ... which we redirect to. print $q->redirect( "http://www.tuxedo.org/~esr/jargon/html/$href" );

In reply to Jargon file of the day by Dog and Pony

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.