dr_jgbn,
For example, grab 85.11, it is within 0.5 of 85.4

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.

#!/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; } } }
Cheers - L~R

In reply to Re: simple search and print by Limbic~Region
in thread simple search and print by dr_jgbn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.