in reply to Re^4: Formatting dates while parsing CSV
in thread Add leading zeros to days/months in dates while parsing CSV

The problem is that the array slice doesn't return undefs when slicing an empty list, it just doesn't return anything:
$ perl -wE 'say for ()[2, 1, 0]' $ perl -wE 'say for ("a")[2, 1, 0]' Use of uninitialized value in say at -e line 1. Use of uninitialized value in say at -e line 1. a

Easy fix: supply the missing fields:

$_ = sprintf '%04d-%02d-%02d', ((split m:/:), (0) x 3)[ 2, 0, 1 ] for +@fields[ 10, 14, 24, 26 ];

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^6: Formatting dates while parsing CSV
by BigRedEO (Acolyte) on Jun 14, 2016 at 15:50 UTC
    So just adding the "(0) x3" will add zeros to any empty date fields, but format if there is an actual date?
      it appends a list of three elements (each containing a zero). So if the split returns a list of three, you end up with six elements (where you take the first three and ignore the rest); if there's nothing to split, you end up with the three freshly appended zeroes.

      Probably exactly what you want.