Hi Perl Monkers, I wrote a stupid code (see below) to combine two files and it obviously is wrong. I am not very familiar with Perl Join or grep and can't seem to figure out the code from scratch using these functions. ANy help perl monkers?
1st file: pizza pickle omellete coke blackforest croissant 2nd file: salt pizza 1 salt pickle 1 pepper omelette 1 pepper pickle 1 I want is: (If ingredient in file 2 is not found in food from file 1, +annotate it as "0" instead of "1"). salt pizza 1 salt pickle 1 salt omellette 1 salt coke 0 salt blackforest 0 salt croissant 0 sugar pizza 0 sugar pickle 0 sugar omellette 0 sugar coke 1 sugar blackforest 1 sugar croissant 0 I wrote this which is obviously wrong: open(INPUTR,"<$1file") || die "Can't open \$1file for reading.\n"; while($line=<INPUTR>){ chomp $line; $food = $line; open(INPUTR1,"<$2file") || die "Can't open \$2file for reading +.\n"; while($line1=<INPUTR1>){ chomp $line1; @toks = split(/\t/, $line1); $ingredient = uc$toks[0]; $food1 = uc$toks[1]; $linemod = $line1; if ($food1 !~ $food){ $linemod = $ingredient."\t".$food."\t"."0"; } } close(INPUTR1); print OUTD $linemod."\n"; }
In reply to Is it Perl "join" that can help me? by angerusso
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |