Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Jargon file of the day

by Dog and Pony (Priest)
on Apr 25, 2002 at 08:34 UTC ( #161891=snippet: print w/ replies, xml ) Need Help??

Description: 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

#!/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( "$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( "$href" );
Comment on Jargon file of the day
Download Code

Back to Snippets Section

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://161891]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2015-12-01 12:06 GMT
Find Nodes?
    Voting Booth?

    My keyboard shows this many letters:

    Results (7 votes), past polls