Last time I checked, 85.4 + .5 is 85.9 which is still less than 85.11. I will assume for now that was just a typo.
Since you do not say how large these files are, I will assume memory is no object. Since you do not say if the tab delimited file has more than two fields, I will assume that the name is in the first field and the second field is the number. Finally, I will assume run-time speed is not critical.
Cheers - L~R#!/usr/bin/perl use strict; use warnings; open (NUMBERS, '<', "numbers.txt") or die "Unable to open numbers.txt +for reading : $!"; open (NAMES, '<', "names.txt") or die "Unable to open names.txt for re +ading : $!"; my %numbers = map {chomp; $_ => 1} <NUMBERS>; my %names = map {chomp; split /\t/ , $_ , 2} <NAMES>; for my $name ( keys %names ) { my $names_number = $names{$name}; for my $number ( keys %numbers ) { my $delta = abs $number - $names_number; if ( $delta <= .5 ) { print "$name : $names_number is within range of $number\n" +; last; } } }
In reply to Re: simple search and print
by Limbic~Region
in thread simple search and print
by dr_jgbn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |