943,935 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 1936
  • Perl RSS
Jul 25th, 2007
0

Perl script modification needed...

Expand Post »
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!



perl Syntax (Toggle Plain Text)
  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;
Reputation Points: 10
Solved Threads: 0
Light Poster
Syakoban is offline Offline
46 posts
since Jan 2006
Jul 26th, 2007
0

Re: Perl script modification needed...

I knew I should have copyrighted that script.
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Jul 26th, 2007
0

Re: Perl script modification needed...

see other forum where you have this question posted.
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: cgi to javascript
Next Thread in Perl Forum Timeline: plz explain me wht does this script means.It is a perl script.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC