Click to See Complete Forum and Search --> : PHP to Perl
feichter
11-20-2005, 12:03 PM
Hello there
I need to rewrite a script from php to perl and have a couple of problems:
- what is the equivalent to
"$the_days[$j] = strftime("%a, %d %b %Y", strtotime("+$jump days"));"
- and what is equivalent to "foreach($the_days as $eachday)"
Many thanks to you all
Jeff Mott
11-20-2005, 04:01 PM
$the_days[$j] = strftime("%a, %d %b %Y", strtotime("+$jump days"));
use POSIX ();
my $jump_days = 3; # or whatever it will be
POSIX::strftime('%a, %d %b %Y, gmtime(time() + 3600 * $jump_days));
and what is equivalent to "foreach($the_days as $eachday)"
for my $eachday (@the_days)
feichter
11-20-2005, 05:30 PM
Many thanks. Worked very well.
Another problem:
$unix = $eachday . " " . $time . ":" . $minute . ":" . $seconds; //$eachday equals a date in the dd/mm/yyyy format
$unix = strtotime($unix);
How do I convert the latter?
You probably guessed by now; I don't know what I'm doing .....
Jeff Mott
11-20-2005, 09:18 PM
$unix = $eachday . " " . $time . ":" . $minute . ":" . $seconds; //$eachday equals a date in the dd/mm/yyyy formatThis line can be used exactly, except for the comment. In Perl comments are denoted by a # character.
$unix = strtotime($unix);I know there is an equivalent, though I don't know it off the top of my head and I'm too lazy to look it up (perldoc.perl.org if you would like to check for more info). The main reason I don't want to look it up is because I actually believe this step could be made easier by a design change. The time() function returns the current date in seconds since the system's epoc. The gmtime() function can derive the second, minute, hour, day, day of the week, month, etc. from this single numerical value, which still allows you to easily manipulate the time and date, as well as provide an easy way to convert the time and date to a string later. My advice is to retain this value for as long as possible, even within database records. It should only be converted to a string when you are finally ready to print it.
feichter
11-21-2005, 02:33 PM
Many thanks again Jeff for your help.
The problem with "$unix = strtotime($unix);" is that $unix is not the current time but a variable in the "$unix = $eachday . " " . $time . ":" . $minute . ":" . $seconds;" format.
Hence, $unix could be "21 Nov 2005 8:0:0" or "22 Nov 2005 9:0:0".
Again many thanks for your help this far.