#!/usr/bin/perl -w

use strict;
use DBI;
use Data::Dump qw/dump/;
use Algorithm::CheckDigits;
use Text::Unaccent;

my $c = DBI->connect("dbi:CSV:","","", { RaiseError => 1, f_ext => '.csv', f_encoding => 'utf-8' }) || die $dbi::errstr;

my $s = $c->prepare(qq{
select * from brucosi_2011_ISVU
});
$s->execute;

while( my $row = $s->fetchrow_hashref ) {

	my $nick = sprintf '%s%s%s'
		, substr($row->{ime},0,1)
		, substr($row->{prezime},0,1)
		, $row->{jmbag} =~ m/^0036/
			? substr($row->{jmbag},4,-1)
			: substr($row->{jmbag},0,-1)
	;

	$nick = lc unac_string('utf-8', $nick);

	print "$nick ", $row->{jmbag},$/;
	
	warn "# $nick row = ",dump($row),$/;
}
