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

ch1 has asked for the wisdom of the Perl Monks concerning the following question:

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'