in reply to simple search and print
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; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: simple search and print
by pzbagel (Chaplain) on Feb 24, 2004 at 23:39 UTC | |
by Limbic~Region (Chancellor) on Feb 24, 2004 at 23:43 UTC | |
|
Re: Re: simple search and print
by fizbin (Chaplain) on Feb 25, 2004 at 08:42 UTC |