bNathan has asked for the wisdom of the Perl Monks concerning the following question:

Hello can anyone help the syntax of these localtime lines. They were originally written for Windows Perl But I am looking to convert them to UNIX. should it all be in lower case?

$tm = localtime;

($DAY, $MONTH, $YEAR, $HH, $MM, $SS) = ($tm->mday, $tm->mon+1, $tm->year+1900, $tm->hour, $tm->min, $tm->sec); use Date::Pcalc qw(Add_Delta_DHMS);

($YEAR2, $MONTH2, $DAY2, $HH2, $MM2, $SS2) = Add_Delta_DHMS( $YEAR, $MONTH, $DAY, $HH, $MM, $SS, 0, 0, 20, 1);

my $mydate2 = Date::EzDate->new("$MONTH2/$DAY2/$YEAR2 $HH2:$MM2:$SS2");

Replies are listed 'Best First'.
Re: $tm = localtime;
by VinsWorldcom (Prior) on Feb 15, 2017 at 16:52 UTC

    Perl is Perl (for the most part) - they should work fine on Windows and Unix with no changes. That said, I'm not familiar with the modules Date::Pcalc or Date::EzDate, if they use XS with specific Windows API calls there may be issues on Unix.

    Have you tried running the commands as-is on Unix? What errors (if any) did you get?

      use Strict;

      BEGIN not safe after errors--compilation aborted at /home/urmaster/www/cgi-bin/regproducts_process.pl line 205.

      205 use Date::Pcalc qw(Add_Delta_DHMS);<?p>

        BEGIN not safe after errors--compilation aborted at /home/urmaster/www/cgi-bin/regproducts_process.pl line 205.

        Thanks for this message. Unfortunately that is only the last line of the error block and only tells us where the problem happened and not what it was. Why not tell us the previous couple of error messages so we can see what it doesn't like about Date::Pcalc? Maybe it isn't installed or in the wrong place or with the wrong version or has a missing dependency or ...

        I'm assuming use Strict is use strict in your program and that your are using Time::Piece in order for $tm = localtime to be an object that you can call $tm->mday, $tm->mon+1, etc.