danny wrote:
> they want a script that displays a certain image depending
> on the day of the week and the time of day.
The "trick" is to decide how you will tell your program which DJ is
working which day/hour. There are LOTS of ways you can do that.
If your schedule is not very granular (ie, everything can be defined in
whole hours) you can incorporate something like this, which sacrifices
a small amount of efficiency (but over a very tiny data structure) for
something that's easy to define and easy to override for oddball
schedule changes. This creates a matrix (7 days x 24 hourly time
slots):
#!/usr/bin/perl
use strict; use warnings;
use CGI qw{ img };
my %dj_img;
foreach my $day(1..5) { #weekday schedule
map {$dj_img{$day}{$_} = 'fatguy.jpg' } ( 0.. 5); #Fred- m'night-6
map {$dj_img{$day}{$_} = 'barney.jpg' } ( 6..

; #Barney-morning
map {$dj_img{$day}{$_} = 'wilma.jpg' } ( 9..15); #Wilma- midday
map {$dj_img{$day}{$_} = 'betty.jpg' } (16..19); #Betty-afternoon
map {$dj_img{$day}{$_} = 'redhead.jpg' } (20..23); #Pebbles- night
}
foreach my $day(0,6) { #weekend schedule
map {$dj_img{$day}{$_} = 'bambam.jpg'} (0..9); #BamBam-w'end am
#etc.
}
# Now somewhere in our CGI script, we print the image tags:
print img( { -src => $dj_img{(localtime)[6]}{(localtime)[2]} });
# DAY HOUR
--
David Filmer (
http://DavidFilmer.com)