http://qs321.pair.com?node_id=494889


in reply to Re^2: Parsing and modifying CSV files
in thread Parsing and modifying CSV files

Another way would be to use the conditional operator inside a loop
# field number for sizes SM MD LG XL my @fno =(9,12,15,18); while (<DATA>) { ## file2 my @data = split(',',$_); my $ky = $data[0]; if (exists $stock{$ky}) { # check each size for my $sz (0..3){ $data[$fno[$sz]] = ( $stock{$ky}[$sz] eq '0' ) ? '' : '0' ; } } print (join(',', @data)); }
poj

Replies are listed 'Best First'.
Re^4: Parsing and modifying CSV files
by poj (Abbot) on Sep 26, 2005 at 21:18 UTC
    If you substitute $sz with 0 the expression becomes $data[$fno[0]] and because $fno[0] = 9 this equates to $data[9] If the expression $stock{$ky}[0] eq '0' is true then $data[9] = '' else $data[9] = '0'
    poj
Re^4: Parsing and modifying CSV files
by Anonymous Monk on Sep 26, 2005 at 20:49 UTC
    Can you explain $data[$fno$sz] = ( $stock{$ky}$sz eq '0' ) ? '' : '0' ; ?

    Is it setting the value of the array to 0 or ''? I don't understand the brackets around $sz.