Random entry

| Perl | 0 Comments

For many many months now, the random link at the top of this page just below the banner hasn't been working. I decided to fix it once and for all.

First of all I redefined the link to refer to a new CGI script mt_random.pl which I wrote myself using good old Perl. Here is how the new link is defined:

<a href="/cgi-bin/mt_random.pl?blog_id=1" title="Jump to a completely random place on this blog...">Random</a>

Of course the whole random magic of the situation is the Perl script mt_random.pl itself, which looks like this:

#!/usr/bin/perl -w
use DBI;
use CGI;
use strict;

my $q = new CGI;

my $format_url = "/%d/%0.2d/%s.html";

my $hostname = 'localhost';
my $database_name = 'db_name';
my $user = 'db_usr';
my $password = 'db_password';

my $dsn = "dbi:mysql:database=$database_name;host=$hostname";

my $blog_id = $q->param('blog_id') || 1;

my $dbh = DBI->connect($dsn, $user, $password) or die "Can't connect to $dsn: $DBI::errstr";

my $sql = <<EOF;
  date_format( entry_created_on, '%Y' ) AS entry_year,
  date_format( entry_created_on, '%m' ) AS entry_month
  entry_blog_id = $blog_id
  entry_status = 2
  author_id = entry_author_id
ORDER BY rand( )

my $sth = $dbh->prepare($sql);

my $ref = $sth->fetchrow_hashref;

print $q->redirect(sprintf($format_url, $ref->{entry_year}, $ref->{entry_month}, $ref->{entry_basename}));

You can now try it out yourself by clicking on the link above, and if you cannot find it then clicking here.

Pretty amazingly magical don't you think?

Leave a comment

Random entries

Here are some random entries that you might be interested in:

Recent Assets

  • embedding-rust-in-nodejs-applications.png
  • finally-golf-again.jpg
  • corona-virus.png
  • long-walk.jpg
  • zonnepanelen.png
  • UC-0122abb7-1b51-422a-9e9b-56c5f86ee741.jpg
  • screenshot-users.rust-lang.org-2020.02.png
  • napolean-the-great.png
  • screenshot-askubuntu.com-2020.01.png
  • construct3.png
  • array-tally-ruby-2.7.png
  • ng-be-2019.png

Golf Handicap


This personal weblog was started way back on July 21, 2001 which means that it is 7-21-2001 old.

So far this blog contains no less than 2388 entries and as many as 1877 comments.

Important events

Graduated from Stanford 6-5-1979 ago.

Kiffin Rockwell was shot down and killed 9-23-1916 ago.

Believe it or not but I am 10-11-1957 young.

First met Thea in Balestrand, Norway 6-14-1980 ago.

Began well-balanced and healthy life style 1-8-2013 ago.

My father passed away 10-20-2000 ago.

My mother passed away 3-27-2018 ago.

Started Gishtech 04-25-2016 ago.