Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: problem in looping

by hbm (Hermit)
on Aug 13, 2012 at 19:10 UTC ( #987184=note: print w/ replies, xml ) Need Help??


in reply to problem in looping

This should get you close, though it assumes the two input files have the same number of lines.

use strict; use warnings; my @f1 = get_lines("1.txt"); my @f2 = get_lines("2.txt"); open(my $out1, ">", "3.txt") or die; open(my $out2, ">", "4.txt") or die; for my $i (0..$#f1){ if (abs($f1[$i]->[1]-$f2[$i]->[1])>1){ print $out1 "$f1[$i]->[0]\n"; print $out2 "$f2[$i]->[0]\n"; } } close $out1; close $out2; sub get_lines { my $file = shift; my @lines; open(my $fh, "<", $file) or die("Unable to open $file: $!"); while(<$fh>){ chomp; /(\d+)$/; push @lines, [ $_, $1 ]; } close $fh; return @lines; }


Comment on Re: problem in looping
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (13)
As of 2015-07-01 18:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (16 votes), past polls