Link to home
Start Free TrialLog in
Avatar of shragi
shragiFlag for India

asked on

perl date conversion

Hi - I am trying to convert effective date format from 11/20/2014 to 20141120.
I am writing that as a part of my script, and please check the attached script.

When i use the below script and run it seperately it works but when I use it as a part of my script it fails and gives me error message saying "can't use string ("Time::Piece") as an array ref while "Strict refs" in use at c:/Strawberry/perl/lib/Time/Piece.pm line 452, <INFILE> line 5"


use strict;
use warnings;
use Time::Piece;
my $dt = Time::Piece->strptime('01/20/2014', '%m/%d/%Y');
print $dt->strftime('%Y%m%d');
            
let me know what needs to be modified in my script.

Thanks
TESTSCRIPT.txt
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shragi

ASKER

That did not work, I got the below error when i modified
"error parsing time at C:/strawberry/perl/lib/time/piece.pm line 469, <INLINE> line 5"


my $dt = Time::Piece->strptime('$effectiveDate', '%m/%d/%Y');
print $dt->strftime('%Y%m%d');

also tried             
my $dt = Time::Piece->strptime('$effectiveDate', '%m/%d/%Y');
print $dt->strptime('%Y%m%d');

Thanks
You did not remove the ' ' around $effectiveDate
As ozo said, you need to remove the single quotes around the $effectiveDate variable.  You are trying to convert the literal string $effectiveDate (which will obviously fail since it is not a date) rather than the value of $effectiveDate.