in reply to Array of variables
Try:
$Variables[$X]=$Year."-".$Months{$Month} ."-" . $Day ;
Also see sprintf for formatting text strings (e.g.: $Day = sprintf('%02d', $Day);)
But really you should avoid manipulating dates by hand. There are plenty of modules that do it better, faster and more safely. See for example DateTime::Format::Strptime. This will give you a tool to read in a date using whatever format you have it in, transform it in some way if desired, and print it out again in a different format. For example:
Output:use strict; use warnings; use feature 'say'; use DateTime::Format::Strptime; my $date = 'Apr 23 2017 11:56:42'; my $parser = DateTime::Format::Strptime->new( pattern => '%b %d %Y %T' +, on_error => 'croak' ); my $dt = $parser->parse_datetime( $date ); say $dt->strftime('%F');
2017-04-23
Hope this helps!
Update: Added DT and sprintf examples
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Array of variables
by Michael W (Initiate) on Apr 27, 2017 at 16:09 UTC | |
by 1nickt (Canon) on Apr 27, 2017 at 16:15 UTC |