#!/usr/bin/perl use DBI; use IO::File; use strict; my $db = "CAMDPAMS"; my $host = "192.168.8.10"; my $file = "world_coord.txt"; #my $file = shift; my @fn; my $sql; my $fh = new IO::File; my $dbh = DBI ->connect("dbi:Pg:dbname=$db;host=$host","olegk","4Q2073gl",{AutoCommit=>0,RaiseError=>1,ChopBlanks=>1}); $dbh->do("truncate table mis.\"country_poligon_test\""); my $sth1 = $dbh->prepare("select \"Id\",\"CountryName\" from mis.\"country_name\";"); my $sth = $dbh->prepare("INSERT INTO mis.\"country_poligon_test\"(\"CountryId\",\"Coordinates\") VALUES (?,?)"); my @cntr; my @coord; open(FI,'<',"$file"); my @strings=; close(FI); foreach my $line (@strings){ chomp $line; my @tmp = split(":",$line); push(@cntr,$tmp[0]); push(@coord,$tmp[1]); } $sth1->execute ; while(my @rows = $sth1->fetchrow_array){ for (my $i = 0; $i <@cntr; $i++) { if( $rows[1] eq $cntr[$i]){ # if( $rows[1] eq 'Ukraine'){ # print "$cntr[$i]|\t|$rows[0]|\t|$rows[1]|\n"; $coord[$i] =~ s/[^,\w\$]//go; # print "$coord[$i]\n"; my $tt = "{$coord[$i]}"; $sth->execute($rows[0],$tt); } } } $sth->finish; $dbh->commit; $dbh->disconnect; print "1\n";