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 |
|
|
use Data::Dump qw/dump/; |
9 |
|
|
use YAML qw/DumpFile/; |
10 |
|
|
use Text::CSV; |
11 |
|
|
|
12 |
|
|
my $debug = 0; |
13 |
|
|
|
14 |
|
|
my $path = shift @ARGV || die "usage: $0 file.csv\n"; |
15 |
|
|
|
16 |
|
|
my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute. |
17 |
|
|
or die "Cannot use CSV: ".Text::CSV->error_diag (); |
18 |
|
|
|
19 |
|
|
open my $fh, "<:encoding(utf8)", $path or die "$path: $!"; |
20 |
|
|
while ( my $row = $csv->getline( $fh ) ) { |
21 |
|
|
|
22 |
|
|
my ( $ulica, $grad ) = split(/\s*,\s*/, $row->[8]); |
23 |
|
|
|
24 |
|
|
my $info = { |
25 |
|
|
jmbg => $row->[2], |
26 |
|
|
adresa_ulica => $ulica, |
27 |
|
|
adresa_grad => $grad, |
28 |
|
|
tel_fixed => $row->[9], |
29 |
|
|
tel_mobile => $row->[10], |
30 |
|
|
spol => substr($row->[2],9,3) < 500 ? 'M' : 'F', |
31 |
|
|
}; |
32 |
|
|
|
33 |
|
|
warn dump($row, $info); |
34 |
|
|
#DumpFile( "yaml/$uuid.yaml", $hash ); |
35 |
|
|
} |
36 |
|
|
$csv->eof or $csv->error_diag(); |
37 |
|
|
close $fh; |
38 |
|
|
|