Tuesday, February 9, 2010

Randomize Image Display using PERL

From HTML side:

<img src="/cgi-bin/myimage">

From PERL side (myimage):

#!/usr/local/bin/perl

print "Content-type: image/gif\n\n";

$pic[0] = "image0.gif";
$pic[1] = "image1.gif";
$pic[2] = "image2.gif";

$rndm = int(rand()*3);

open(PIC, "./../image/$pic[$rndm]");
binmode(PIC);
binmode(STDOUT);

while (<PIC>) {
print $_;
}
close(PIC);


This is neat. Seldom a programmer reveals this simple but neat secret.

No comments:

Post a Comment