hi,
i am having trouble with the second "if" statement in the script below. i only want to process the lines in the "fb.tsv" file where "Scan" appears in column 10. but in some cases the word "Scan" appears in lines i do not want to process (in say, column 20).
obviously the line if (/Scan/) will process all lines where "Scan" appears in both 10th and 20th columns. but for some reason the commented out line below returns correct values but appears to go through the file several times, and i only want it to go through the file once. this is probably a simple problem for someone who is more familiar with perl than me. any suggestions?
thanks,
niki
#!/usr/bin/perl
#
@dbarray1 = ();
@dbarray5 = ();
open(FA, "fa.txt") || die "Cannot find the FA file. \n";
while ($line = <FA>)
{
chomp($line);
@dbarray = split (/ /,$line);
push(@dbarray1, $dbarray[1]);
push(@dbarray5, $dbarray[5]);
}
close(FA);
open(FB, "fb.tsv") || die "Cannot find the FB file. \n";
while ($line = <FB>)
{
chomp($line);
@array = split (/\s*\|/, $line);
foreach (@array)
{
($array[103] =~ m/^DB(\d{1,2})/);
$db_no = $1;
for ($i=0; $i<=$#dbarray1; $i++)
{
if (($dbarray1[$i] == $db_no) && (/Pointed/))
{
$pointed_result = $array[16]*$dbarray5
+[$i];
}
# if ($array[10] =~ m/Scan/)
if (/Scan/)
{
$scan_result = $array[16]*$dbarray5[$i
+]+20;
}
}
}
}
close(FB);
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.