in reply to csv parsing with multiple missing values/multiple commas

You should enable warnings and actually look at them.

if($str_check = undef)

This check is never true and always overwrites $str_check.

I'm not sure whether your problems are actually related to the code you've shown. The problems seem to be mostly data and logic related. Please help us help you better and show us the loop where you process your data, the warnings and errors you get and the output you expect.

Replies are listed 'Best First'.
Re^2: csv parsing with multiple missing values/multiple commas
by f77coder (Beadle) on Aug 02, 2014 at 15:30 UTC

    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.

      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