angerusso has asked for the wisdom of the Perl Monks concerning the following question:
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is it Perl "join" that can help me?
by choroba (Cardinal) on May 13, 2012 at 07:31 UTC | |
|
Re: Is it Perl "join" that can help me?
by davido (Cardinal) on May 13, 2012 at 07:56 UTC | |
|
Re: Is it Perl "join" that can help me?
by tobyink (Canon) on May 13, 2012 at 08:47 UTC | |
|
Re: Is it Perl "join" that can help me?
by AnomalousMonk (Archbishop) on May 13, 2012 at 23:29 UTC |