Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Comparing FILE1 value to FILE2 range and printing matches

by biohisham (Priest)
on Oct 18, 2014 at 04:09 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-26 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found