BigRedEO has asked for the wisdom of the Perl Monks concerning the following question:
I have a Perl script to scrub data in CSV files to then be loaded into MySQL Tables. Several of the fields are Date fields that were originally m/d/yyyy - with no leading zeros. I formatted those fields for MySQL using -
$_ = join '-', (split /\//)[2,0,1] for @fields[10,14,24,26];which worked just fine to load the MySQL tables. But now I'm being told these same CSV files may be used in other depts for things like SQL or other programs and they will need leading zeros. I tried using sprintf, but I'm not quite sure how to use it while parsing nor with a scalar variable. This is what I attempted in place of my original line of code, but get "unitialized value" -
$_ = sprintf '%04d-%02d-%02d', split m:/: for @fields[10,14,24,26];What am I doing wrong here? (sorry, parsing and scalars get me confused)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Formatting dates while parsing CSV
by choroba (Cardinal) on Jun 14, 2016 at 14:27 UTC | |
by BigRedEO (Acolyte) on Jun 14, 2016 at 14:35 UTC | |
by Corion (Patriarch) on Jun 14, 2016 at 14:44 UTC | |
by BigRedEO (Acolyte) on Jun 14, 2016 at 15:16 UTC | |
by choroba (Cardinal) on Jun 14, 2016 at 15:35 UTC | |
| |
by choroba (Cardinal) on Jun 14, 2016 at 15:25 UTC | |
| |
|
Re: Add leading zeros to days/months in dates while parsing CSV
by hippo (Archbishop) on Jun 14, 2016 at 14:33 UTC | |
|
Re: Add leading zeros to days/months in dates while parsing CSV
by runrig (Abbot) on Jun 14, 2016 at 16:12 UTC |