zetetes has asked for the wisdom of the Perl Monks concerning the following question:
my $sth = $dbh->prepare("SELECT PlzOrt, Ortsbezeichnung, PlzGemein +de, 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, cl +k_percent, clk_days, clk_plz, gde_name, clk_price, prc_id, obt_id, cl +k_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 fi +le: $!"; while (<FH>) { chomp; @content = split /;/; if (exists $hash_ref_ort->{'$content[7]'}) { $content[18] = $hash_ref_ort->{'$content[7]'}->{'GemeindeI +d'}; $content[6] = $hash_ref_ort->{'$content[7]'}->{'PlzGemeind +e'}; } 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<br>";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: updating array with matching value of hash
by Roy Johnson (Monsignor) on May 06, 2004 at 14:26 UTC |