Hi,

Someone put together a small perl script for me that uses day and time to determine which of two images to display (open.gif or closed.gif). I need to modify the script to also include a hyperlink to open.html or closed.html so that if the open image is displayed it uses the open.html link and the closed to closed.html. The corresponding web page that loads the image is ultra basic, with a link to the .pl script as the image tag.

Can anyone help a real perl novice (me!) with this one?

Thanks guys!

#!/usr/bin/perl
use CGI::Carp qw/fatalsToBrowser/;

use strict;
use warnings;

# path to folder where images are
# assumes an image named open.gif and closed.gif
my $path = '/home/fireplug/public_html/images/';

# time in military format 0-23
# first number is opening time
# second number is closing time
# 24-24 indicates always closed
# server is central standard time so time is adjusted minus 1 hour
my %schedule = (
Sun => [9,11],
Mon => [10,11],
Tue => [10,11],
Wed => [10,11],
Thu => [10,11],
Fri => [10,11],
Sat => [24,24]
);

# default value
my $image = 'closed.gif';

# get the day and hour
my ($day, $hour) = (split(/ /,scalar localtime))[0,3];
$hour = (split(/:/,$hour))[0];

# check the day and hour
if ($schedule{$day}[0] <= $hour && $schedule{$day}[1] > $hour) {
$image = 'open.gif';
}

#print appropriate MIME type header
print "Content-type: image/gif\n\n";

open(FH,"$path$image") or die "$!";
binmode(FH);
print while (<FH>);
close(FH);
exit;

Recommended Answers

All 2 Replies

I knew I should have copyrighted that script.

see other forum where you have this question posted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.