From ba9db0ee32da23d842c080b6202a9f26f4cd7cfa Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 13 Jul 2010 13:21:17 +0000 Subject: [PATCH 1/1] parse new csv files with 1st year students --- bin/csv2yaml-upisi2010.pl | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 bin/csv2yaml-upisi2010.pl diff --git a/bin/csv2yaml-upisi2010.pl b/bin/csv2yaml-upisi2010.pl new file mode 100755 index 0000000..3f5b19e --- /dev/null +++ b/bin/csv2yaml-upisi2010.pl @@ -0,0 +1,38 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +# 2010-07-13 Dobrica Pavlinusic + +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; + -- 2.20.1