For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Freelance > March 2004 > Display CGI









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Display CGI
dailyshorts

2004-03-19, 1:26 pm

I have this script to display a photo depending on what day of the Julian
Calendar:

#!/usr/bin/perl
use CGI;
$q = CGI->new();
$day = (localtime(time()))[7]+1;
&show_image;

sub show_image {
print "Content-type: text/html\n\n";
print " <table cellpadding=0 cellspacing=0 border=0>\n";
print " <tr align=center>\n";
print " <td align=center>\n";
print '<img src="thumb/' . substr ('000' . $day,-3) . '.jpg" border="0"
alt="Photo of the Day">';
print " </tr>\n";
print " </table>\n";
exit;
}

How can it be changed to only reflect the day of just one w?



Steve

2004-03-19, 1:26 pm

"dailyshorts" <admin@REMOVEdailyshorts.com> wrote in message news:<PYSdne1sueZyYI_dRVn-jQ@comcast.com>...
> I have this script to display a photo depending on what day of the Julian
> Calendar:
>
> #!/usr/bin/perl
> use CGI;
> $q = CGI->new();
> $day = (localtime(time()))[7]+1;
> &show_image;
>
> sub show_image {
> print "Content-type: text/html\n\n";
> print " <table cellpadding=0 cellspacing=0 border=0>\n";
> print " <tr align=center>\n";
> print " <td align=center>\n";
> print '<img src="thumb/' . substr ('000' . $day,-3) . '.jpg" border="0"
> alt="Photo of the Day">';
> print " </tr>\n";
> print " </table>\n";
> exit;
> }
>
> How can it be changed to only reflect the day of just one w?


The code above doesn't run, the quotes are screwy in the img tag line.

Do you mean a different picture for each day of the w ?

If so the code below does run, but is still ugly in a number of respects

You need images called sun.jpg, mon.jpg etc

Hope I don't upset the locals by doing this; if you want to use this code please
donate $10 to medecin sans frontiers.

steve

#!/usr/bin/perl

use CGI;
$q = CGI->new();
# $day = (localtime(time()))[7]+1;
# replaced line above with 1 below
$day = qw(sun mon tue wed thur fri sat)[(localtime)[6]];

&show_image;

sub show_image {
print "Content-type: text/html\n\n";
print " <table cellpadding=0 cellspacing=0 border=0>\n";
print " <tr align=center>\n";
print " <td align=center>\n";
#print '<img src="thumb/' . substr ('000' . $day,-3) . '.jpg" border="0";
# replaced squiffy line above with 1 below
print qq[<img src="thumb/$day.jpg" border="0"
alt="Photo of the Day of the w">\n];
print " </tr>\n";
print " </table>\n";
exit;
}
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com