/[informatika.old]/fill.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /fill.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Wed Apr 12 08:11:45 2000 UTC (23 years, 11 months ago) by dpavlin
Branch: MAIN
File MIME type: text/plain
.

1 #!/usr/local/bin/perl -w
2
3 die "Kao argument ime datoteke (npr. xxxx.txt) !!" if (! defined($ARGV[0]));
4 $file=$ARGV[0];
5
6 use DBI;
7
8 $type=$file;
9 $type=~s/\.[^\.]+//g;
10
11 #---
12
13 my $mydbh = DBI->connect("DBI:Pg:dbname=informatika","","") || die $DBI::errstr;
14 open(IN,"< $file") || die "ne mogu otvoriti $file";
15 while (<IN>) {
16 chomp;
17 s/\015//g; # kill cr
18
19 tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/; # 1250 -> iso8859-2
20
21 s/^"//;
22 s/"$//;
23 s/\t"/\t/g;
24 s/"\t/\t/g;
25 s/ */ /g;
26
27 next if (/^#/);
28
29 @arr = split(/\t/,$_);
30
31 if ($type eq "otvoreni") {
32 $sql_insert="insert into otvoreni (ime,prezime,tojzoj,odjel,lokacija) values ('$arr[0]','$arr[1]','$arr[2]','$arr[3]','$arr[4]') ";
33 } elsif ($type eq "lokacije") {
34 $sql_insert="insert into lokacije (naziv) values ('$arr[0]') ";
35 } elsif ($type eq "kontant_osobe") {
36 @foo = ( 'a'..'z','0'..'9','A'..'Z' );
37 $passwd="";
38 for (1..8) { $passwd=$passwd.$foo[int(rand($#foo))] };
39 ($ime,$prezime) = split(/ /,$arr[1],2);
40 $sql_insert="insert into kontakt_osobe (ime,prezime,e_mail,passwd) values ('$ime','$prezime','$arr[0]','$passwd') ";
41 } elsif ($type eq "tipovi_racunala") {
42 $sql_insert="insert into tipovi_racunala (tip) values ('$arr[0]') ";
43 } elsif ($type eq "statusi") {
44 $sql_insert="insert into status_tip (opis) values ('$arr[0]') ";
45 } else {
46 die "Nepoznat tip datoteke $type !!";
47 }
48
49 print "--$sql_insert\n";
50 $mydbh->do("$sql_insert") || die $mydbh->errstr();
51
52 }
53
54 print "\n";

  ViewVC Help
Powered by ViewVC 1.1.26