/[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

Annotation of /bin/csv2yaml-upisi2010.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 98 - (hide annotations)
Tue Jul 13 14:29:59 2010 UTC (13 years, 10 months ago) by dpavlin
File MIME type: text/plain
File size: 1359 byte(s)
check jmbg

1 dpavlin 96 #!/usr/bin/perl
2    
3     use warnings;
4     use strict;
5    
6     # 2010-07-13 Dobrica Pavlinusic <dpavlin@rot13.org>
7    
8 dpavlin 98 # http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number
9    
10 dpavlin 96 use Data::Dump qw/dump/;
11     use YAML qw/DumpFile/;
12     use Text::CSV;
13    
14     my $debug = 0;
15 dpavlin 97 my $dir = 'yaml/hrEduPersonUniqueNumber_JMBG';
16 dpavlin 96
17 dpavlin 97 mkdir $dir unless -e $dir;
18    
19 dpavlin 96 my $path = shift @ARGV || die "usage: $0 file.csv\n";
20    
21 dpavlin 98
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 dpavlin 96 my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute.
35     or die "Cannot use CSV: ".Text::CSV->error_diag ();
36    
37     open my $fh, "<:encoding(utf8)", $path or die "$path: $!";
38     while ( my $row = $csv->getline( $fh ) ) {
39    
40     my ( $ulica, $grad ) = split(/\s*,\s*/, $row->[8]);
41    
42     my $info = {
43 dpavlin 97 prezime => $row->[0],
44     ime => $row->[1],
45 dpavlin 96 jmbg => $row->[2],
46 dpavlin 97 datum_rodjenja => $row->[3],
47     email => $row->[4],
48 dpavlin 96 adresa_ulica => $ulica,
49     adresa_grad => $grad,
50     tel_fixed => $row->[9],
51     tel_mobile => $row->[10],
52     spol => substr($row->[2],9,3) < 500 ? 'M' : 'F',
53     };
54    
55 dpavlin 97 my $uuid = $row->[2];
56     DumpFile( "$dir/$uuid.yaml", $info );
57 dpavlin 98 warn "$uuid ", valid_jmbg( $row->[2] ) ? 'OK' : 'INVALID', "\n";
58    
59 dpavlin 96 }
60     $csv->eof or $csv->error_diag();
61     close $fh;
62    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26