![]() |
| ||
| who here can do perl? you guys ready for this, this is the worlds bigest problem, i will be super happy if you can help me here is some code i have for a countdown script " #!/usr/bin/perl ############################################################################## # Define Variables # @from_date = (yyyy,mm,dd,hh,mm,ss); # Which means: (year,month,day,hour,minute,second) @from_date = (2006,2,15,00,00,XX); # Done ############################################################################## $ENV{'QUERY_STRING'} =~ s/%2C/,/g; $ENV{'QUERY_STRING'} =~ s/=//g; if ($ENV{'QUERY_STRING'}) { @from_date = split(/,/, $ENV{'QUERY_STRING'}); } # Define when various things occur, different dates, etc... &define_dates; # Calculate the Differences in the two dates &calc_dates; # Make Sure we don't get negative times.. That's not cool... &no_negative; # Top of HTML Page Information &html_header; # We don't want it to say 1 Years, now, do we? Of course not! &proper_english; # End of HTML Page Information &html_trailer; ##################################### # Subroutines sub define_dates { ($f_year,$f_month,$f_day,$f_hour,$f_minute,$f_second) = @from_date; ($second,$minute,$hour,$day,$month,$year,$wday,$yday,$isdst) = localtime(time()); $year += 1900; &leap_year_check; @months = ("XX","January","February","March","April","May","June","July", "August","September","October","November","December"); @days = ("XX","1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th", "11th","12th","13th","14th","15th","16th","17th","18th","19th", "20th","21st","22nd","23rd","24th","25th","26th","27th","28th", "29th","30th","31st"); @days_in_month = (31,$feb_days,31,30,31,30,31,31,30,31,30,31); $date_term = "$months[$f_month] $days[$f_day]"; unless ($f_year eq 'XX') { $date_term = "$date_term, $f_year"; } unless ($f_hour eq 'XX') { $date_term = "$date_term $f_hour"; } unless ($f_minute eq 'XX') { if ($f_minute < 10) { $date_term = "$date_term:0$f_minute"; } else { $date_term = "$date_term:$f_minute"; } } unless ($f_second eq 'XX') { if ($f_second < 10) { $date_term = "$date_term:0$f_second"; } else { $date_term = "$date_term:$f_second"; } } $current_date = "$months[($month + 1)] $days[$day], $year $hour"; if ($minute < 10) { $current_date = "$current_date:0$minute"; } else { $current_date = "$current_date:$minute"; } if ($second < 10) { $current_date = "$current_date:0$second"; } else { $current_date = "$current_date:$second"; } } sub leap_year_check { if ($year % 4 != 0 || ($year % 100 == 0 && $year % 400 != 0)) { $feb_days = "28"; } else { $feb_days = "29"; } } sub calc_dates { $real_year = ($f_year - $year); $real_month = (($f_month - 1) - $month); $real_day = ($f_day - $day); $real_hour = ($f_hour - $hour); $real_minute = ($f_minute - $minute); $real_second = ($f_second - $second); } sub no_negative { if ($real_second < 0) { $real_second = ($real_second + 60); $real_minute--; } if ($real_minute < 0) { $real_minute = ($real_minute + 60); $real_hour--; } if ($real_hour < 0) { $real_hour = ($real_hour + 24); $real_day--; } if ($real_day < 0) { $real_day = ($real_day + @days_in_month[$month]); $real_month--; } if ($real_month < 0) { $real_month = ($real_month + 12); $real_year--; } } sub proper_english { unless ($f_year eq 'XX') { if ($real_year eq '1') { print "$real_year Year<br>\n"; } else { print "$real_year Years<br>\n"; } } unless ($f_month eq 'XX') { if ($real_month eq '1') { print "$real_month Month<br>\n"; } else { print "$real_month Months<br>\n"; } } unless ($f_day eq 'XX') { if ($real_day eq '1') { print "$real_day Day<br>\n"; } else { print "$real_day Days<br>\n"; } } unless ($f_hour eq 'XX') { if ($real_hour eq '1') { print "$real_hour Hour<br>\n"; } else { print "$real_hour Hours<br>\n"; } } unless ($f_minute eq 'XX') { if ($real_minute eq '1') { print "$real_minute Minute<br>\n"; } else { print "$real_minute Minutes<br>\n"; } } unless ($f_second eq 'XX') { if ($real_second eq '1') { print "$real_second Second<br>\n"; } else { print "$real_second Seconds<br>\n"; } } } sub html_header { print "Content-type: text/html\n\n"; print "<html><head><title>Countdown to : $date_term</title></head>\n"; print "<body><center><h1>Countdown till the day we legaly own our empire on : $date_term</h1>\n"; print "<hr>\n"; } sub html_trailer { print "<hr>\n"; print "It is currently $current_date\n"; print "</center>\n"; print "</body></html>\n"; } " but this uses the servers time, my server time, this is set to Australian WST and i am in england london, can some one edit this script so it uses client side time. this one is a pain in the ass for me |
| ||
| Re: who here can do perl? The world's biggest problem? I hope that's not true. Next time you post, please put your code in code tags, such as [code]A bunch of code[/code]. Furthermore, in order to answer your question, code isn't really needed. Now, to answer your question... There isn't a way to get the client time unless the client tells you what the time is on their system. Since there isn't a way to force the client to send the current time on the machine with it's request header, you'll have to find a different way to get that information. I recommend using Javascript. There are two different ways to use Javascript to get the current time on the page: have it pass the time as part of the URL string or have Javascript print the time on the page itself. Each method has it's strengths and weeknesses. Passing the time as a URL encoded variable allows you to do fancy stuff with the time in Perl before printing the page but the time on the page will reflect that time that the page with the link was loaded, not when the current page was generated. Having Javascript on the page allows the time to be current and could automatically update the time dynamically but results in there being no purpose to the page being generated by Perl (in other words, a standard HTML page could do the exact same thing). The following is a complete HTML page that will show the current time (see it here): <html>Notice that this did not require any Perl code. The following HTML page uses Javascript to create a link that will link to a program that will use the passed in time as part of the page generation (see it here): <html>The code I used in showClientTime.cgi is really simple and simply returns the time in a plain text format. #!/usr/bin/perlI would recommend just using Javascript for your problem. The times when you want to use passed Javascript URL-encoded variables is when you are generating an image. Using passed variables and image generating code, you can have images that show the current client time on the page. Does that help you at all? |
| ||
| Re: who here can do perl? that does help for some things greatly, however the scipt is a countdown from a form take a look ... here ... i need to make it use the time of the person browsing the page if i can do that by putting a java script of the html page before the pl script then that would be great! |
| ||
| Re: who here can do perl? I think you still don't fully understand the limitation here. You cannot use the client time in a Perl script unless you already have the client time passed in. This means that you cannot load a page and magically get the client time from no where. If you want to do manipulations with the client time, use Javascript. I produced an end of year script using nothing but Javascript (example). |
| ||
| Re: who here can do perl? Quote:
|
| ||
| Re: who here can do perl? Why is it so important that you do this with Perl? Javascript was made for the very reason of giving web programmers access to information on the client-side of the web. Making really roundabout ways of getting the client time to the Perl code without requiring page reloads or page ugliness is doing nothing more than making what you want to do hard on yourself. I've given you examples of how to pass the client-side information to a Perl script using Javascript, and I've shown you how to use Javascript to do the entire process. What more would you like me to show you? |
| ||
| Re: who here can do perl? right the script's used on here are the sort i think i should use but how can i use the time from the java you have given on the example in my code to form my countdown? |
| ||
| Re: who here can do perl? I'm still a bit confused about why you want to do this with Perl. Are you wanting to learn how to do date and time manipulation with Perl? Is it a personal challenge? Did you tell someone that you could, so now you are trying to prove it? Even if you made a page that used Javascript to link to a Perl script so that you got the client time, you still couldn't dynamically update it as I had shown in the last page I made, you need to use Javascript to do that. Perl is useful for doing server-side stuff, not client-side. Since you want to manipulate client-side data, there isn't a reason to not use Javascript for the task. While knowledge of how to do everything with a specific language is a good skill to have, knowing what language to use to solve a certain problem is much more valuable. So... Why do you want to use Perl for this task? What do you expect Perl to do that Javascript can't? If you let me know what it is that causes you to want to use Perl, I can give you the information you need, otherwise I'm just throwing code at you. |
| ||
| Re: who here can do perl? i got the script when my site was young, it does what i want mostly there is a form on the page for people to make there own count downs, and then there is a link to get the countdown to 2006 and my birthday. when you want my birthday its set as defalt (www.domail.net/cgi-bin/countdown.pl to view click here or if you want 2006 it does www.domain.net/countdown.pl?yyyy,mm,dd,hh,mm,ss (year,month,day,hour,mins,seconds) the script just takes the current date then works out the difference bettwen the two (i believe) then displays a count down (that does not refresh or change it's just form when you went to the page all i would like to do is somehow pass the client time to it so that it does not use my australien server time (sorry about any mis-spellings here) |
| ||
| Re: who here can do perl? Keep in mind that Javascript is good for client-side things and Perl is good for server-side things. Knowing this, the best design would be to use Perl to create Javascript code based upon form selections. I made a sample script to show this in action (example): #!/usr/bin/perlIs this more of what you are looking for? |
| All times are GMT -4. The time now is 5:14 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC