Question 1
open INFILE, "$ARGV[0]"; @aTryptic = <INFILE>; close INFILE; shift @aTryptic; for ($i=0;$i<@aTryptic;$i++) { $accSeq = SplitFields($aTryptic[$i], 'split'); $aTryptic[$i] =~ s/\r\n$/\n/g; chomp $aTryptic[$i]; $hTryptic{$accSeq} = $aTryptic[$i]; $aTryptic[$i] = $accSeq; } open INFILE, "$ARGV[1]"; @aSemiTryptic = <INFILE>; close INFILE; shift @aSemiTryptic; for ($i=0;$i<@aSemiTryptic;$i++) { $accSeq = SplitFields($aSemiTryptic[$i], 'split'); $aSemiTryptic[$i] =~ s/\r\n$/\n/g; chomp $aSemiTryptic[$i]; $hSemiTryptic{$accSeq} = $aSemiTryptic[$i]; $aSemiTryptic[$i] = $accSeq; }
What it does is just open a file passes into an array, then replace each cell with some part of the whole and also create a hash.
Question is, how can I make it into a sub so that I don't have a duplicate?
Question 2
2 files of data (strings of data that is separated by tabs, e.g. name\taddress\tetc). I need to compare the 2 I create 2 arrays and 2 hashes, the arrays contain just the field that I want to compare e.g. name and the hashes are created with the name as key and the rest is the values.
I compare the 2 arrays and if there is a common name I'll get the value from 1 hash and print in into a file, if there is none then I get the value from the other hash and print into the same file.
foreach $one (@arrayA) { chomp $one; $found = 0; foreach $two (@arrayB) { chomp $two; if ($one eq $two) { print "$hashB{$two}"; $found = 1; last; } } if ($found == 0) { print "$hashA{$one}"; } }
Is this the best way to do it?
Thanks.
Desmond
In reply to Can I make a sub for this? by sandrider
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |