#!/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" );
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|