/[webpac2]/trunk/bin/isi-merge.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/bin/isi-merge.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1283 by dpavlin, Fri Sep 18 18:35:50 2009 UTC revision 1342 by dpavlin, Fri Oct 15 15:30:26 2010 UTC
# Line 3  Line 3 
3  use warnings;  use warnings;
4  use strict;  use strict;
5  use autodie;  use autodie;
6    use Digest::MD5 qw(md5_hex);
7    use Digest::SHA1 qw(sha1_hex);
8    use Data::Dump qw(dump);
9    
10    my $use_sha1 = $ENV{SHA1} || 1;
11    
12  my @files = @ARGV;  my @files = @ARGV;
13  @files = glob '/tmp/isi.*-*.txt' unless @files;  @files = glob '/tmp/isi.*-*.txt' unless @files;
14    
15  my $path = '/tmp/isi.full.txt';  my $path = '/tmp/isi.full.txt';
16    
17    warn "# ", $#files + 1, " files to $path sha:$use_sha1\n";
18    
19  open(my $out_fh, '>', $path);  open(my $out_fh, '>', $path);
20  print $out_fh "FN ISI Export Format\nVR 1.0\n";  print $out_fh "FN ISI Export Format\nVR 1.0\n";
21    
22    my $rec;
23    my $nr = 0;
24    
25    my $md5;
26    
27    my $report;
28    
29  foreach my $file ( sort {  foreach my $file ( sort {
30          my $a_r = $1 if $a =~ m{(\d+)-\d+};          my $a_r = $1 if $a =~ m{(\d+)-\d+};
31          my $b_r = $1 if $b =~ m{(\d+)-\d+};          my $b_r = $1 if $b =~ m{(\d+)-\d+};
32          $a_r <=> $b_r;          $a_r <=> $b_r;
33  } @files ) {  } @files ) {
34          warn $file;          print STDERR $file;
35    
36            push @{ $report->{files} }, $file;
37    
38          open(my $fh, '<', $file);          open(my $fh, '<', $file);
39          while(<$fh>) {          while(<$fh>) {
40                  next if m/^(FN|VR|EF)/;                  next if m/^(FN|VR|EF)/;
41    
42                  print $out_fh $_;                  if ( ! m/^[\r\n]+$/s ) {
43                            $rec .= $_;
44                    } else {
45                            $nr++;
46                            my $digest = $use_sha1 ? sha1_hex $rec : md5_hex $rec;
47                            if ( my $times = $md5->{$digest} ) {
48                                    print STDERR 'd';
49                                    $report->{file}->{$file}->{duplicates}++;
50                            } else {
51                                    print $out_fh $rec . $_;
52                                    $report->{file}->{$file}->{records}++;
53                                    $report->{total_records}++;
54                                    print STDERR '.';
55                            }
56    
57                            $md5->{$digest}++;
58                            $rec = '';
59                    }
60          }          }
61            warn "\n";
62  }  }
63    
64  print $out_fh "EF\n";  print $out_fh "EF\n";
65  close $out_fh;  close $out_fh;
66    
67  warn "# $path ", -s $path;  
68    warn "# $path ", -s $path, dump $report;
69    

Legend:
Removed from v.1283  
changed lines
  Added in v.1342

  ViewVC Help
Powered by ViewVC 1.1.26