/[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.2 - (show annotations)
Mon Jun 19 06:03:23 2000 UTC (22 years, 7 months ago) by dpavlin
Branch: MAIN
Changes since 1.1: +11 -0 lines
File MIME type: text/plain
kontakt_osobe.txt podrka

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 } elsif ($type eq "kontakt_osobe_ic") {
46 @foo = ( 'a'..'k', 'm'..'z', '2'..'9', 'A'..'H', 'J'..'N',
47 'P'..'Z', '!', '#', '$', '%', '&', '(', ')', '=',
48 '-', '/', '?' );
49 srand;
50 $passwd="";
51 for (1..8) {
52 $ch=$foo[int(rand($#foo))];
53 $passwd=$passwd.$ch;
54 }
55 $sql_insert="insert into kontakt_osobe (ime,prezime,e_mail,passwd,prava) values ('$arr[0]','$arr[1]','$arr[2]','$passwd',64) ";
56 } else {
57 die "Nepoznat tip datoteke $type !!";
58 }
59
60 print "--$sql_insert\n";
61 $mydbh->do("$sql_insert") || die $mydbh->errstr();
62
63 }
64
65 print "\n";

  ViewVC Help
Powered by ViewVC 1.1.26