Question:
how can i get perl to print time?
tommy
2012-10-13 15:03:01 UTC
ive been looking through perl tutorials and found this one which would be great for my html page.
but the output comes out as 9:14:42, Wed Dec 28, 2005 and i only want a hour and minutes format.
how can i simplify the code from the tutorial to just a hour/minute format?

#!/usr/local/bin/perl
@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
@weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
$year = 1900 + $yearOffset;
$theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year";
print $theTime;

Also, how can i make my html and perl go together ??
here is my html page. so i have the html which has input boxes for name and age and with the action set to a.pl. This means the data should be sent to that perl file and perl will send back the user input name and time right?






Name:
Age:




Four answers:
ʄaçade
2012-10-13 15:33:27 UTC
Your perl code looks pretty much right. Format as you choose.



$theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year";



printf ("%02d:%02d\n" , $hour, $minute ); # HH:MM



Perl and HTML together:

In order for this to work right, the Perl code must be "server-side". That is, the web server runs it, not the client browser.



Make sure your web server has Perl execution enabled. Some do not.



Normally, you would have the Perl code executed by the server as if it were the URL's web page. Then the Perl code outputs ALL the HTML from within. You can also do it PHP-style, but at this point, just have your script generate the whole page:



#!/usr/bin/perl -w



print "\n";

print "\n";

print "yadda yadda\n";

print "\n";



print "\n";

print "\n";



print "

\n";

print "You see where I am going with this, right?\n";

print "

\n";



print "\n";
Dubist Arschlock
2012-10-13 16:48:21 UTC
first question: $theTime = "$hour:$minute



2nd: go to www.cpan.org and type in MASON in the search window.
burket
2016-12-27 00:05:14 UTC
you may no longer use < to verify strings. you'll be able to desire to apply lt, le, cmp additionally, your code is crap via fact $x=a isn't syntactically outstanding. Please upload use strict; use warnings; to the best of your software and only placed up finished runnable examples.
Wise Idiot
2012-10-13 15:03:51 UTC
google


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...