#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2016
    Posts
    1
    Rep Power
    0

    Perl Date Format


    I am parsing a CSV file with several date fields, which are all in the format 1/29/2016 (for example).
    I had already reformatted the date fields in my file (using Perl) so the CSV files could then be used to load into MySQL tables, using this code -

    Code:
    $_ = join '-', (split /\//)[2,0,1] for @fields[1,5,9];
    Which gives me 2016-1-29, but I also need to pad with zeros for the month and date. So I tried this -
    Code:
    $_ = sprintf '%3$04d-%02d-%02d', split m:/: for @fields[1,5,9];
    but that's throwing all kinds of errors. Having a lot of trouble understanding sprintf and how to use it while parsing through a file.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Apr 2009
    Posts
    2,231
    Rep Power
    1296
    Cross posted and answered on perlmonks.

IMN logo majestic logo threadwatch logo seochat tools logo