/[virtual-ldap]/bin/csv2yaml-upisi2010.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 /bin/csv2yaml-upisi2010.pl

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

revision 97 by dpavlin, Tue Jul 13 14:15:50 2010 UTC revision 98 by dpavlin, Tue Jul 13 14:29:59 2010 UTC
# Line 5  use strict; Line 5  use strict;
5    
6  # 2010-07-13 Dobrica Pavlinusic <dpavlin@rot13.org>  # 2010-07-13 Dobrica Pavlinusic <dpavlin@rot13.org>
7    
8    # http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number
9    
10  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
11  use YAML qw/DumpFile/;  use YAML qw/DumpFile/;
12  use Text::CSV;  use Text::CSV;
# Line 16  mkdir $dir unless -e $dir; Line 18  mkdir $dir unless -e $dir;
18    
19  my $path = shift @ARGV || die "usage: $0 file.csv\n";  my $path = shift @ARGV || die "usage: $0 file.csv\n";
20    
21    
22    sub valid_jmbg {
23            my $jmbg = shift;
24            return 0 unless $jmbg =~ /^\d{13}$/;
25            my @c = split(//, $jmbg);
26            my $S=0;
27            for (my $i=0;$i<6;$i++){
28                    $S+= (7-$i)*($c[$i]+$c[6+$i]);
29            }
30            my $checksum = 11-($S%11);
31            return $checksum == $c[12];
32    }
33    
34  my $csv = Text::CSV->new ( { binary => 1 } )  # should set binary attribute.  my $csv = Text::CSV->new ( { binary => 1 } )  # should set binary attribute.
35          or die "Cannot use CSV: ".Text::CSV->error_diag ();          or die "Cannot use CSV: ".Text::CSV->error_diag ();
36    
# Line 39  while ( my $row = $csv->getline( $fh ) ) Line 54  while ( my $row = $csv->getline( $fh ) )
54    
55          my $uuid = $row->[2];          my $uuid = $row->[2];
56          DumpFile( "$dir/$uuid.yaml", $info );          DumpFile( "$dir/$uuid.yaml", $info );
57          warn "$uuid\n";          warn "$uuid ", valid_jmbg( $row->[2] ) ? 'OK' : 'INVALID', "\n";
58    
59  }  }
60  $csv->eof or $csv->error_diag();  $csv->eof or $csv->error_diag();
61  close $fh;  close $fh;

Legend:
Removed from v.97  
changed lines
  Added in v.98

  ViewVC Help
Powered by ViewVC 1.1.26