BigRedEO has asked for the wisdom of the Perl Monks concerning the following question:
The Time::Piece lines are not working. I'm not getting any errors, but they are not changing the Date within the DATETIME variable for each record from MM/DD/YYYY 00:00 to YYYY-MM-DD 00:00 as I need. What am I missing here?while($line = <$FH>) { # split the fields, concatenate the first three fields, # and add it to the beginning of each line in the file chomp($line); my @fields = split(/,/, $line); unshift @fields, join '_', @fields[0..2]; $_ = join '-', (split /\//)[2,0,1] for $fields[14]; $_ = join '-', (split /\//)[2,0,1] for $fields[20]; $_ = join '-', (split /\//)[2,0,1] for $fields[23]; $_ = Time::Piece->strptime($fields[38],'%m/%d/%Y %H:%M')->strftime +('%Y-%m-%d %H:%M'); $_ = Time::Piece->strptime($fields[39],'%m/%d/%Y %H:%M')->strftime +('%Y-%m-%d %H:%M'); push @data, \@fields; }
Update
I have found the correct way to this - updated belowNow I've run into another problem for which I'll have to open a separate question!while($line = <$FH>) { # split the fields, concatenate the first three fields, # and add it to the beginning of each line in the file chomp($line); my @fields = split(/,/, $line); unshift @fields, join '_', @fields[0..2]; $_ = join '-', (split /\//)[2,0,1] for $fields[14,20,23]; $_ = Time::Piece->strptime($_,'%m/%d/%Y %H:%M')->strftime('%Y-%m-% +d %H:%M') for @fields[38,39]; push @data, \@fields; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Formatting date while parsing CSV
by fishmonger (Chaplain) on Apr 12, 2016 at 18:36 UTC | |
|
Re: Formatting date while parsing CSV
by GotToBTru (Prior) on Apr 12, 2016 at 18:39 UTC | |
|
Re: Formatting date while parsing CSV
by fishmonger (Chaplain) on Apr 12, 2016 at 18:59 UTC | |
|
Re: Formatting date while parsing CSV
by Marshall (Canon) on Apr 12, 2016 at 19:08 UTC | |
by BigRedEO (Acolyte) on Apr 12, 2016 at 19:15 UTC | |
by haukex (Archbishop) on Apr 12, 2016 at 22:20 UTC |