Solved

perl date conversion

Posted on 2014-12-15
4
200 Views
Last Modified: 2014-12-20
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
0
Comment
Question by:shragi
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40500446
Time::Piece->strftime('$effectiveDate', '%m/%d/%Y');
should be
Time::Piece->strptime($effectiveDate, '%m/%d/%Y');
0
 

Author Comment

by:shragi
ID: 40500491
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
0
 
LVL 84

Expert Comment

by:ozo
ID: 40500496
You did not remove the ' ' around $effectiveDate
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 40500650
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.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now