my $sth = $dbh->prepare("SELECT PlzOrt, Ortsbezeichnung, PlzGemeinde, GemeindeId FROM ortzugemeinde"); $sth->execute; my $hash_ref_ort = $sth->fetchall_hashref('Ortsbezeichnung'); $sth->execute; my $hash_ref_plz = $sth->fetchall_hashref('PlzOrt'); $sth = $dbh->prepare( q{ INSERT INTO clk_clicks (clk_year, clk_month, obj_id, own_id, clk_percent, clk_days, clk_plz, gde_name, clk_price, prc_id, obt_id, clk_total, clk_object, clk_detail, clk_pdf, clk_direct, clk_vmail, clk_fmail, gde_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?) }); my @content; my @table; open FH, "< mydir/ImportFile_200201.txt" or die "Unable to open file: $!"; while () { chomp; @content = split /;/; if (exists $hash_ref_ort->{'$content[7]'}) { $content[18] = $hash_ref_ort->{'$content[7]'}->{'GemeindeId'}; $content[6] = $hash_ref_ort->{'$content[7]'}->{'PlzGemeinde'}; } elsif (exists $hash_ref_plz->{$content[6]}) { $content[18] = $hash_ref_plz->{$content[6]}->{'GemeindeId'}; $content[6] = $hash_ref_plz->{$content[6]}->{'PlzGemeinde'}; } else { $content[18] = 0; } $sth->execute(@content); push @table, [@content]; } close FH; $dbh->commit; $dbh->disconnect; print "ok
";