Advertisement
cd62131

abs

Jul 25th, 2014
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.92 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use feature 'say';
  5. sub error {
  6.   my ($x1, $y1, $d1, $x2, $y2, $d2) = @_;
  7.   return undef if abs($x1 - $x2) > .20001 || abs($y1 - $y2) > .20001;
  8.   return [$d1, $d2];
  9. }
  10. my $data1 = []; my $data2 = [];
  11. open my $d1, '<data1.dat' or die; open my $d2, '<data2.dat' or die;
  12. while (<$d1>) {
  13.   next if /\Ax座標/;
  14.   chomp; my @d = split; push @$data1, \@d;
  15. }
  16. while (<$d2>) {
  17.   next if /\Ax座標/;
  18.   chomp; my @d = split; push @$data2, \@d;
  19. }
  20. close $d1; close $d2;
  21. my $size1 = scalar @$data1; my $size2 = scalar @$data2;
  22. open my $out, '>output.dat' or die;
  23. for (my $i = 0; $i < $size1; $i++) {
  24.   for (my $j = 0; $j < $size2; $j++) {
  25.     my @d = (
  26.       $data1->[$i][0], $data1->[$i][1], $data1->[$i][2],
  27.       $data2->[$j][0], $data2->[$j][1], $data2->[$j][2]
  28.     );
  29.     my $error = error @d;
  30.     next unless defined $error;
  31.     say $out join "\t", @$error;
  32.   }
  33. }
  34. close $out;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement