Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: extract values from file if greater than value

by Marshall (Canon)
on Jun 15, 2016 at 19:43 UTC ( [id://1165785]=note: print w/replies, xml ) Need Help??


in reply to Re^2: extract values from file if greater than value
in thread extract values from file if greater than value

Ok here is something to consider that produces your output to the best of my understanding at the moment:
#!/usr/bin/perl use warnings; use strict; # this uses a "trick" to open an in memory file # like a file on the disk for testing purposes my $file1 =<<END; 1 19002930 0.74 1 19002931 -0.12 END my $file2 =<<END; 1 19002930 0.84 0.12 0.94 1 19002931 0 -.20 .12 END open (my $fh1, '<', \$file1) or die "$!"; open (my $fh2, '<', \$file2) or die "$!"; my $lineFile1; my $lineFile2; # compare line by line of both files # stop if either file "runs out of lines" # assumes that say: line 232 of file 1 goes with line 232 of file 2 while (defined ($lineFile1=<$fh1>) and defined ($lineFile2=<$fh2>)) { my ($line1Col1, $line1Col2, $line1Col3) = split ' ', $lineFile1; my ($line2Col1, $line2Col2, @file2rest) = split ' ', $lineFile2; if ($line1Col1 == $line2Col1 and $line1Col2 == $line2Col2) { print "$line1Col1 $line1Col2 "; print join" ", grep{ $_>=$line1Col3 }@file2rest; print "\n"; } else { # col1 and col2 didn't match, so we do nothing # you can delete this else clause entirely } } __END__ prints: 1 19002930 0.84 0.94 1 19002931 0 .12
Could be written shorter, but I think that this what you want and it will run very quickly (compared with R).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-23 07:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found