parse new csv files with 1st year students
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 13 Jul 2010 13:21:17 +0000 (13:21 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 13 Jul 2010 13:21:17 +0000 (13:21 +0000)
bin/csv2yaml-upisi2010.pl [new file with mode: 0755]

diff --git a/bin/csv2yaml-upisi2010.pl b/bin/csv2yaml-upisi2010.pl
new file mode 100755 (executable)
index 0000000..3f5b19e
--- /dev/null
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+# 2010-07-13 Dobrica Pavlinusic <dpavlin@rot13.org>
+
+use Data::Dump qw/dump/;
+use YAML qw/DumpFile/;
+use Text::CSV;
+
+my $debug = 0;
+
+my $path = shift @ARGV || die "usage: $0 file.csv\n";
+
+my $csv = Text::CSV->new ( { binary => 1 } )  # should set binary attribute.
+       or die "Cannot use CSV: ".Text::CSV->error_diag ();
+
+open my $fh, "<:encoding(utf8)", $path or die "$path: $!";
+while ( my $row = $csv->getline( $fh ) ) {
+
+       my ( $ulica, $grad ) = split(/\s*,\s*/, $row->[8]);
+
+       my $info = {
+               jmbg => $row->[2],
+               adresa_ulica => $ulica,
+               adresa_grad  => $grad,
+               tel_fixed => $row->[9],
+               tel_mobile => $row->[10],
+               spol => substr($row->[2],9,3) < 500 ? 'M' : 'F',
+       };
+
+       warn dump($row, $info);
+       #DumpFile( "yaml/$uuid.yaml", $hash );
+}
+$csv->eof or $csv->error_diag();
+close $fh;
+