Alex on Camel, Egypt
Butchers in Moshi, Tanzania
Remarkable Rocks, Kangaroo Island
Summer Palace, China
Dorota on Brighton Beach

About the Author

author photo

Now I'm curious what social networking site I can steal a profile of myself from... be right back.

See All Posts by This Author

HTML Random Image Script

Well I wanted to create a random image display for one of my sites, but all I could find were JavaScript random image scripts, the problem with the ones I found were that the script had to contain all the list of images, it had to be in the body tag too so couldnt intergrate the Java Script and the image list into an external file.

I had a good look for PHP random image scripts, but nothing as simple as I wanted, so I decided now was the time to brush up on my perl and create my own.

#! /usr/local/bin/perl -w
$basedir = "http://www.code-d.com/papa-smurf/random/";
@files = ("strip01.jpg", "strip02.jpg", "strip03.jpg",);
$num = rand(@files);
print "Location: $basedir$files[$num]\n\n";

All you need to do to use this script is obviously call it something like randomimage.pl, set your absolute path to Perl, and then stick it in your cgi-bin and set the permissions to 755.

All you need to do to use this script is obviously call it something like randomimage.pl, set your absolute path to Perl, and then stick it in your cgi-bin and set the permissions to 755. To call a random image you just reference it like a normal image.

All you need to do to use this script is obviously call it something like randomimage.pl, set your absolute path to Perl, and then stick it in your cgi-bin and set the permissions to 755. To call a random image you just reference the script like you would for a normal image. If you want to see an example please check out my papa smurf site.

Popularity: 5% [?]

  • http://www.stonehenge.com/merlyn/ Randal L. Schwartz

    No need for that srand() line in any release of Perl from the past five years. In fact, it destroys the even better randomization that’s already built in.
    Perhaps the code you show is cargo-culted from a decade ago, when that was indeed good advice. Perhaps you should ignore most of the rest of the code you got from the same place. {grin}

  • http://www.stonehenge.com/merlyn/ Randal L. Schwartz

    No need for that srand() line in any release of Perl from the past five years. In fact, it destroys the even better randomization that’s already built in.
    Perhaps the code you show is cargo-culted from a decade ago, when that was indeed good advice. Perhaps you should ignore most of the rest of the code you got from the same place. {grin}

  • http://www.code-d.com Alex Asigno

    Hi Randal, thanks for that i have takent that line out and the images load a bit quicker now too :)

    Your right my perl days are nearly 5 years out of date hehe

  • http://www.code-d.com Alex Asigno

    Hi Randal, thanks for that i have takent that line out and the images load a bit quicker now too :)

    Your right my perl days are nearly 5 years out of date hehe

blog comments powered by Disqus