Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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
Domain Nodelet?
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 scrutinizing the Monastery: (1)
As of 2021-10-21 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (82 votes). Check out past polls.

    Notices?