I'm new to perl... So, please take it easy on me.
I've two files:

file1
-------------------------
qty,model,size,color,sku 224,128,MD,B,840197082997 0,128,LG,B,840197083000 0,128,XL,B,840197083017


and file2
-------------------------
v_products_model,v_attribute_options_id_1,v_attribute_options_name_1_1 +,v_attribute_values_id_1_1,v_attribute_values_price_1_1,v_attribute_v +alues_name_1_1_1,v_attribute_options_id_2,v_attribute_options_name_2_ +1,v_attribute_values_id_2_1,v_attribute_values_price_2_1,v_attribute_ +values_name_2_1_1,v_attribute_values_id_2_2,v_attribute_values_price_ +2_2,v_attribute_values_name_2_2_1,v_attribute_values_id_2_3,v_attribu +te_values_price_2_3,v_attribute_values_name_2_3_1,v_attribute_values_ +id_2_4,v_attribute_values_price_2_4,v_attribute_values_name_2_4_1 128,1,Download,0,,TEXT,2,Size,2,,SM,3,0,MD,4,0,LG,5,0,XL


If an item from file1 is in-stock, I need to update the field to the left of the size(SM,MD,LG,XL) to zero in file2.


In this example, the desired output would be:
128,1,Download,0,,TEXT,2,Size,2,,SM,3,0,MD,4,,LG,5,,XL

Here is my attempt but it doesn't work:
#!/usr/bin/perl open(I1,"IM.csv") or die "IM.csv: $!"; $_ = <I1>; # read column headings while (<I1>) { # get data chomp; push @lines, $_ ; } open(I2,"Attributes-EP2005Sep23-1907.txt") or die "Attributes-EP2005Se +p23-1907.txt: $!"; $_ = <I2>; # read column headings while (<I2>) { # get data chomp; push @lines2, $_ ; } foreach ( @lines ) { my ($qty,$name,$size,$color,$descript) = split /,/; #print "$qty,$name,$size,$color,$descript\n"; if ($qty <= 0){$qty= ''} else{$qty=0}; foreach ( shift(@lines2) ) { my ($v_products_model,$therest) = split(/,/,$_ +,2); print "$v_products_model\n"; if ($v_products_model eq $name){ my ($begin, $end) = split(/.,$size/,$therest); print "$v_products_model,$begin\n"; } else{push @lines2,$_} }

20050924 Janitored by Corion: Added code tags around data

2005-09-25 Retitled by Arunbear, as per Monastery guidelines
Original title: 'Point me in the right direction'


In reply to Parsing and modifying CSV files by ch1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.