1 |
#!/usr/local/bin/perl -w |
2 |
|
3 |
use DBI; |
4 |
|
5 |
#--- |
6 |
|
7 |
my $pgdbh = DBI->connect("DBI:Pg:dbname=informatika","","") || die $DBI::errstr; |
8 |
open(IN,"podjela.txt") || die "ne mogu otvoriti: $!"; |
9 |
while (<IN>) { |
10 |
chomp; |
11 |
s/\015//g; # kill cr |
12 |
|
13 |
tr/ðèæÐÈÆ/¹ð¾èæ©Ð®ÈÆ/; # 1250 -> iso8859-2 |
14 |
|
15 |
$data=$_; |
16 |
|
17 |
if ($data !~ /^\t/) { |
18 |
$sth=$pgdbh->prepare('insert into org_jed (naziv) values (?)'); |
19 |
$sth->execute($data); |
20 |
} else { |
21 |
$data =~ s/^\t//; |
22 |
$sth=$pgdbh->prepare("select last_value from org_jed_id_seq"); |
23 |
$sth->execute; |
24 |
@arr = $sth->fetchrow_array; |
25 |
$sth=$pgdbh->prepare("insert into org_pod_jed (nad_id,pod_naziv) values (?,?)"); |
26 |
$sth->execute($arr[0],$data); |
27 |
|
28 |
} |
29 |
|
30 |
} |
31 |
|
32 |
print "\n"; |