Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Comparing FILE1 value to FILE2 range and printing matches

by biohisham (Priest)
on Oct 18, 2014 at 04:09 UTC ( #1104216=note: print w/replies, xml ) Need Help??


in reply to Comparing FILE1 value to FILE2 range and printing matches

You can read the positions into an array by themsevels, and then open the second file and iterate over the array to find lines where the positions are enclosed within the ranges. That way you open each file only once

use strict; use warnings; open(my $fh1, "<","positions.txt") or die("could not open file $!\n"); my @positions; #hold the positions to be compared while(my $line=<$fh1>){ chomp $line; push @positions,$line; } open(my $fh2, "<","coords_orientation.txt") or die("could not open fil +e $!\n"); while(my $line=<$fh2>){ chomp $line; my @record=split(" ",$line); #split the coords_orientation.txt on +white space foreach my $pos (@positions){ if($pos > $record[0] && $pos <$record[1]){ print "$pos @record\n"; } } }

A 4 year old monk

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1104216]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2020-05-27 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (153 votes). Check out past polls.

    Notices?