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 puts the open.html link on the image and the closed.html link on the closed image. 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;
23 2476
What you want is not possible.
This script is a handler that serves an image depending on the current time. This script is intended to be referenced inside the src value of an image tag. There is no way to effect the enclosing html that refers to this "image" handler.
- Miller
Hmmm... does that mean an entirely new script written in a different way can do the job or that a CGI script can't do it at all? And... can a SSI be used in conjunction with the script to achieve what I need; something like redirecting based on the open or closed image? CGI + javascript?
Thanks!
The solution must be found in the enclosing html, not the image handler. I don't know what is generating the html that is using this image handler, or if it's just static html. But regardless of what is currently generating it, if you want dynamic html, then you're going to have to program it.
- Miller
Thanks Miller.
Currently it is a static html page(s). All the "intelligence" is in the CGI where the time and day are gathered and the appropriate image selected. The html is: - <img src="http://www.site_name.com/cgi-bin/open.pl" width="50" height="20">
I know I'm missing something conceptually here, making this more of a project than it really is but... Are you suggesting dynamic html from a new script that uses the server "intelligence" to both gather the day and time and then write the html code for both image and hyperlink, or some other approach? Would that require SSI to call the CGI or how would it be inserted into an otherwise static page?
Thanks.
Someone put together a small perl script for me
I did the script for you on the webmaster forum.
It's a world of laughter
A world of tears
It's a world of hopes
And a world of fears
There's so much that we share
That it's time we're aware
It's a small world after all
There is just one moon
And one golden sun
And a smile means
Friendship to ev'ryone
Though the mountains divide
And the oceans are wide
It's a small world after all
It's a small world after all
It's a small world after all
It's a small world after all
It's a small, small world
hehehe..... brings back memories of Disneyland :)
what he wants to do could be handled via SSI and a perl script called using the include virtual SSI tag:
<!--#include virtual="../cgi-bin/open.pl" -->
which is cool becuase it allows you to send arguments to the script in the query string so you can get pretty fancy with it.
he has this question posted on yet a different perl forum from this one and from the original one where I wrote the script for him.
It's a world of laughter
A world of tears
It's a world of hopes
And a world of fears
There's so much that we share
That it's time we're aware
It's a small world after all
There is just one moon
And one golden sun
And a smile means
Friendship to ev'ryone
Though the mountains divide
And the oceans are wide
It's a small world after all
It's a small world after all
It's a small world after all
It's a small world after all
It's a small, small world
ROTFLMAO!!!!! It simply amazes me that people think that others only read one forum. I post in more than one myself, I know that Kevin does as I have seen his posts. I mean COME ON PEOPLE!!!
Jeff
You all got bent out of shape for nothing... nothing insidious going on...
I said from the start that someone else wrote the script. I couldn't find the bookmark I had for the forum where it originally was posted, so I searched Google and found some new perl forums, so I posted there. KevinADC IS THE AUTHOR of the script and should be credited 110% for his work.
If this is a big offense to you guys and don't want to help out, say so and I'll ask elsewhere.
Thanks.
Bent out of shape, you wouldn't like it if I were bent out of shape? (Sorry, channeled The Hulk for a second there) No, that was more laughing hillariously at the silliness that some cross posters exert. We know who wrote the script, Kevin said it in his post when he told us he already wrote it for you. ( he he,
If it comes down to it that the question you are posting was answered elsewhere, then say that. Say that you posted and got the question answered elsewhere but cannot remember where so you need to repost it. You would have probably been given the link to the other post by Kevin here.
Regards,
Jeff
He created the original script, but the new issue (links with the images) is still unanswered.
Thanks.
Hello smarsh,
Please do not misconstrue my amusement at the prolific state of Kevin's contributions as a rebuke of your question and situation.
However, I believe that I personally have helped you as much as I can at this time. You're at that stage now where you must decide what technological level that you want to create this new feature at. And that's not something that I generally like to advise people in.
Do you want to use SSI?
CGI?
Javascript?
Some mixture of the above?
shrug,
- Miller
He created the original script, but the new issue (links with the images) is still unanswered.
Thanks.
See post #8 in this thread. Using SSI and a slightly different perl script you can generate the image and the link wihin your shtml document. -
#!/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';
-
my $alt = 'sorry, we are closed';
-
my $page = 'closed.html';
-
-
# 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';
-
$alt = 'we are open';
-
$page = 'open.html';
-
}
-
-
#print appropriate MIME type header
-
print "Content-type: text/html\n\n";
-
print qq{<a href="../$page title="$alt"><img src="../images/$image" alt="$alt"></a>};
-
PS: I accept donations.
PS: I accept donations.
Aaaaalms for the poor......... ***ding - ding***..... Aaaaaalms for the poor.....
Please sir, could you spare a pence or two to pay my 'lectric bill? This coding stuff does use power ya know.
;-|)
Great! This time I got it to run on the 1st try... Thanks!
Donation/compensation... you say tomato I say tomaaato... that's cool.
Give me some details and I'll work on it.
Great! This time I got it to run on the 1st try... Thanks!
Donation/compensation... you say tomato I say tomaaato... that's cool.
Give me some details and I'll work on it.
Glad you go it working. I did spot an error in the last line of the code: - print qq{<a href="../$page title="$alt"><img src="../images/$image" alt="$alt"></a>};
there should be a double-quote after $page: - print qq{<a href="../$page" title="$alt"><img src="../images/$image" alt="$alt"></a>};
check your PM's.
All of a sudden (I think) I'm getting wacky results. I thought I tested the script during open and closed times, yet now nothing makes sense. The server is GMT-6 . I want the open time for Monday to be between 10 and 11 AM, so I set it that way. The only way I can get it to work and show the "open" graphic is by setting it to 6. The close time doesn't seem to work right at all - like setting it to 7 for 11AM (because of the 6 being 10???) it still stays open after 11.
Any thoughts?
This is the current script that as far as I know, I have only "modified" by setting the times for each day of the week. Monday should be [10,11] as well, but I changed that to [6,11] to get the open time to work at the actual 11:00AM. The server checks out to be running the correct time in the central time zone.
I'm lost...
Thanks. - #!/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 time
-
my %schedule = (
-
Sun => [9,11],
-
Mon => [6,11],
-
Tue => [10,11],
-
Wed => [10,11],
-
Thu => [10,11],
-
Fri => [10,11],
-
Sat => [24,24],
-
);
-
-
# default value
-
my $image = 'closed.gif';
-
my $alt = 'sorry, we are closed';
-
my $page = 'closed.html';
-
-
# 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';
-
$alt = 'we are open now';
-
$page = 'open.html';
-
}
-
-
#print appropriate MIME type header
-
print "Content-type: text/html\n\n";
-
-
print qq{<a href="../$page" title="$alt"><img src="../images/$image" alt="$alt"border="0"></a>};
You should offset the time here: - my ($day, $hour) = (split(/ /,scalar localtime))[0,3];
add or subtract the number of seconds from 'time' to off set the server time to your desired time-zone, an example adding 6 hours: - my ($day, $hour) = (split(/ /,scalar localtime(time+21600)))[0,3];
and use the actual hours of open/close in the hash of arrays: - my %schedule = (
-
Sun => [9,11],
-
Mon => [10,11],
-
Tue => [10,11],
-
Wed => [10,11],
-
Thu => [10,11],
-
Fri => [10,11],
-
Sat => [24,24],
-
);
to offset the server time by plus one hour: 60 * 60 * 1 = 3600
localtime(time+3600)
to offset the server time by minus 2 hours: 60 * 60 * 2 = 7200
localtime(time-7200)
I think you get the picture.
I understand the time adjustment: I'm GMT-5 and the server is GMT-6, so if I use time+3600 I effectively adjust the server time to my time zone and the hash arrays schedule is entered based on my local time. But that's not the problem. It's just acting wacky.
I put in the time+3600 adjustment and to test changed the Wed schedule to
because I'm working on it at 6:15PM on Wed. It didn't work though. I had to back down to
to get the "open" image to appear. That's a time difference of 9 hours.
What can be going on?
I asked you to post your current code, in that current code I see this line:
my ($day, $hour) = (split(/ /,scalar localtime))[0,3];
there is no offset. Offset the time how I showed you and use the real hours of business in the hash. If that does not work I am not sure what the problem is.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dynamo |
last post by:
Not sure if this is a php or an html question but I'll post it anyway.
I have multiple thumbnail images on my catalogue page catalogue.php and they are
all hyperlinked to a single page called...
|
by: Wentink |
last post by:
Does anybody have a simple script that let's me popup a picture from a
thumbnail?
The ones i found are all very very complicated and messy in the source...
Thanks,
Tintin
|
by: Allen |
last post by:
I am trying to add an additional photo/hyperlink to the company web
site (I didn't create it) without any luck. The mouseover feature
'highlights' pics by swapping them with another pic using this...
|
by: Nathan Sokalski |
last post by:
I have several System.Web.UI.WebControls.HyperLink Controls which I want to
display as rollover images. I know how to make these manually using the <a>
and <img> tags or the <a> tag and a...
|
by: jon |
last post by:
Hi
This might be an easy one to answer but I have a web form in an ASP.NET
1.1 application with a hand-rolled HTML image button as follows which
opens a help guide in a new window:
<input...
|
by: Bundy |
last post by:
Hi
On my webpages I have replaced the submit button with a rolling submit
button using the script below (Script 1). This script is used by many
of my webpages and is included in a external...
|
by: Nathan Sokalski |
last post by:
I am using the ImageUrl property of the HyperLink control. My image is
large, so I am setting the width/height attributes, but when it renders the
width/height attributes are in the <atag rather...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Many websites have a form or a link you can use to download a file. You click a form button or click...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |