uniq_file.pl 594 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/perl
  2. use 5.020;
  3. use warnings;
  4. use Math::GMPz;
  5. my $file = shift(@ARGV) || die "usage: perl $0 [file]\n";
  6. open my $fh, '<', $file or die "Can't open `$file` for reading: $!";
  7. my %seen;
  8. my @terms;
  9. while (<$fh>) {
  10. next if /^\h*#/;
  11. /\S/ or next;
  12. my $n = (split(' ', $_))[-1];
  13. $n =~ /^[0-9]+\z/ || next;
  14. next if $seen{$n}++;
  15. push @terms, Math::GMPz->new("$n");
  16. }
  17. close $fh;
  18. @terms = sort { $a <=> $b } @terms;
  19. open my $out_fh, '>', $file or die "Can't open `$file` for writing: $!";
  20. foreach my $term (@terms) {
  21. say {$out_fh} $term;
  22. }
  23. close $out_fh;