Hello Perlmonks,
I cannot seem to solve this simplistic piece of code...
I have 2 files; 1 is a list of numbers e.g. 85.11 etc. The second is a list of names and numbers, tab-delimited.
e.g. John Doe 85.4
John Dear 84.2
etc.
What I wish to do is take each number from file 1 and search against file 2. Anything number in file 2 within plus or minus 0.5 of the number in file 1 will cause the name and number of that match to be printed. For example, grab 85.11, it is within 0.5 of 85.4 and not 84.2 so only print out John Doe etc.
Here is my feeble attempt thus far.
while (<FH1>) {
@num=<FH1>;}
close FH1;
foreach $num (@num) {
chomp $num;
while (<FILE2>) {
@marks = split(/\t/, $_);
$x=$marks[0];
$y=$marks[1];
if ($num - $y < 1) {
print OUT "$x\n";
}
}
}
Thanks for you help,
dr_jgbn
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.