Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Parsing and modifying CSV files

by poj (Abbot)
on Sep 25, 2005 at 08:56 UTC ( [id://494889]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://494889]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-25 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found