Perl script modification needed...

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2006
Posts: 43
Reputation: Syakoban is an unknown quantity at this point 
Solved Threads: 0
Syakoban Syakoban is offline Offline
Light Poster

Perl script modification needed...

 
0
  #1
Jul 25th, 2007
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!



  1. #!/usr/bin/perl
  2. use CGI::Carp qw/fatalsToBrowser/;
  3.  
  4. use strict;
  5. use warnings;
  6.  
  7. # path to folder where images are
  8. # assumes an image named open.gif and closed.gif
  9. my $path = '/home/fireplug/public_html/images/';
  10.  
  11. # time in military format 0-23
  12. # first number is opening time
  13. # second number is closing time
  14. # 24-24 indicates always closed
  15. # server is central standard time so time is adjusted minus 1 hour
  16. my %schedule = (
  17. Sun => [9,11],
  18. Mon => [10,11],
  19. Tue => [10,11],
  20. Wed => [10,11],
  21. Thu => [10,11],
  22. Fri => [10,11],
  23. Sat => [24,24]
  24. );
  25.  
  26. # default value
  27. my $image = 'closed.gif';
  28.  
  29. # get the day and hour
  30. my ($day, $hour) = (split(/ /,scalar localtime))[0,3];
  31. $hour = (split(/:/,$hour))[0];
  32.  
  33. # check the day and hour
  34. if ($schedule{$day}[0] <= $hour && $schedule{$day}[1] > $hour) {
  35. $image = 'open.gif';
  36. }
  37.  
  38. #print appropriate MIME type header
  39. print "Content-type: image/gif\n\n";
  40.  
  41. open(FH,"$path$image") or die "$!";
  42. binmode(FH);
  43. print while (<FH>);
  44. close(FH);
  45. exit;
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: Perl script modification needed...

 
0
  #2
Jul 26th, 2007
I knew I should have copyrighted that script.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: Perl script modification needed...

 
0
  #3
Jul 26th, 2007
see other forum where you have this question posted.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC