sort.pl 579 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/perl
  2. use Math::GMPz;
  3. open my $fh, '<', 'data.txt';
  4. my %orig;
  5. while (<$fh>) {
  6. if (/^a\((\d+)\)\s*=\s*(\d+)/) {
  7. $orig{$1} = Math::GMPz->new($2);
  8. }
  9. }
  10. close $fh;
  11. open my $fh2, '<', '/tmp/b.txt';
  12. my %new;
  13. while (<$fh2>) {
  14. if (/^a\((\d+)\)\s*=\s*(\d+)/) {
  15. $new{$1} = Math::GMPz->new($2);
  16. }
  17. }
  18. close $fh2;
  19. foreach my $k (sort { $a <=> $b } keys %new) {
  20. $orig{$k} //= $new{$k};
  21. if ($new{$k} < $orig{$k}) {
  22. $orig{$k} = $new{$k};
  23. }
  24. }
  25. foreach my $k (sort { $a <=> $b } keys %orig) {
  26. print "a($k) = $orig{$k}\n";
  27. }