in reply to Re: csv parsing with multiple missing values/multiple commas
in thread csv parsing with multiple missing values/multiple commas

Hello, I've posted my code.

for this input

11504515,1,,0,7,,29891,32,18,2,5,,1,,,05db9164,207b2d81,09ade5f6,f7322fb9,25c83c98,fbad5c96,c3c334be,0b153874,a73ee510,e25c6d5e,c4d946cf,a671c1e0,96c2b31e,b28479f6,d295078c,5ee88d62,e5ba7672,966c77d8,21ddcdc9,b1252a9d,c336836b,,3a171ecb,9fa3e01a,001f3601,59b96d68

i want this array, blanks/missing values filled with zero 0

11504515,1,0,0,7,0,29891,32,18,2,5,0,1,0,0,05db9164,207b2d81,09ade5f6,f7322fb9,25c83c98,fbad5c96,c3c334be,0b153874,a73ee510,e25c6d5e,c4d946cf,a671c1e0,96c2b31e,b28479f6,d295078c,5ee88d62,e5ba7672,966c77d8,21ddcdc9,b1252a9d,c336836b,,3a171ecb,9fa3e01a,001f3601,59b96d68

this is error

Argument "" isn't numeric in numeric eq (==) at ./test.pl line 91, <GEN2> line 4516.

Replies are listed 'Best First'.
Re^3: csv parsing with multiple missing values/multiple commas
by Corion (Patriarch) on Aug 02, 2014 at 16:44 UTC

    So maybe you can also show us line 91?

    Most likely, you have something like:

    my $cell= $row->[ 10 ]; if( $cell == 42 ) { ... }

    You could fix this by conditionally setting $cell to zero:

    my $cell= $row->[ 10 ]; $cell ||= 0; if( $cell == 42 ) { ... }
      here is line 91
      line 90 my @hash = $csv->names; #returns hash line 91 my @vals = values @hash; #hash to array

        It's highly unlikely that this is the code that produces this error message:

        Argument "" isn't numeric in numeric eq (==) at ./test.pl line 91, <GE +N2> line 4516.

        So most likely, you have different line numbers, but in my opinion, the solution will remain the same. Set elements with the empty string to zero and the comparision will work.