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

Contents of /bin/csv2yaml-upisi2010.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 # 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/;
11 use YAML qw/DumpFile/;
12 use Text::CSV;
13
14 my $debug = 0;
15 my $dir = 'yaml/hrEduPersonUniqueNumber_JMBG';
16
17 mkdir $dir unless -e $dir;
18
19 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.
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 prezime => $row->[0],
44 ime => $row->[1],
45 jmbg => $row->[2],
46 datum_rodjenja => $row->[3],
47 email => $row->[4],
48 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 my $uuid = $row->[2];
56 DumpFile( "$dir/$uuid.yaml", $info );
57 warn "$uuid ", valid_jmbg( $row->[2] ) ? 'OK' : 'INVALID', "\n";
58
59 }
60 $csv->eof or $csv->error_diag();
61 close $fh;
62

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26