Hello,
I recently loaded some data into a database. It worked fine
but it would be slow if I had a larger number
of records to load.

I am only working with four string types(TUP, TDP, TDF, TUF)
that exist in a db table. How can I look them up ahead of time and push
them into a hash (TUP=>1, TDP=>2, TDF=>3, TUF=>4).
That way I could just look up the id in the hash so that I don't have to query the table for every record.
That is what I am presently doing in my prepared statement $sth2.
#!/usr/bin/perl -w use strict; use warnings; use DBI; use Time::localtime; use DateTime; ######################################################## # This script creates new records in the oracle # # database for Taqman oligos. These are # # revised versions of oligos that previously failed # # and now the sequence and oligo_name are ready # # to be inserted into the oligos table. # ######################################################## my $now = DateTime->now(time_zone => 'floating'); my $yesterday = $now->subtract(days=>1); my $year = $yesterday->year; my $month = $yesterday->month; my $month_abbr = uc($yesterday->month_abbr);# uppercase string chars my $day = $yesterday->day; my $year_abbr = substr "$year",2,2; #creation date for loading into the database date fields my $create_date = "$day-$month_abbr-$year_abbr\n"; my $dbh = DBI->connect("DBI:Oracle:jweb", "genes", "biggenes") or die "Couldn't connect to database: " . DBI->errstr; open(my $oligo_file, "irFRP_Oligos.txt") || die "can't open file"; while(<$oligo_file>){ chomp; my @fields = split /\t/; my ($oligo, $seq) = ($fields[0], $fields[1]); # get project name from substring of $oligo # Create records for irregular oligos. Example, 12453TUR2. my $project_name = substr ($oligo,0,5); my $sth1 = $dbh->prepare("select project_id from projects where pr +oject_name = ?"); $sth1->execute($project_name); my @result1 = $sth1->fetchrow(); my $project_id = $result1[0]; # this is where I want to m my $oligos_type_name = substr ($oligo, -4,-1); my $sth2 = $dbh->prepare("select oligos_type_id from oligos_types +where oligos_type_name = ?"); $sth2->execute($oligos_type_name); my @result2 = $sth2->fetchrow(); my $oligos_type_id = $result2[0]; my $sth3 = $dbh->prepare("oligos_sequence.nextval from dual"); my @result3 = $sth3->fetchrow(); my $oligo_id = $result3[0]; my $sth = $dbh->prepare("insert into oligos (oligo_id, project_id, + oligo_type_id, oligo_sequence, oligo_name, oligo_create_user_id, oligo_modify_use +r_id, oligo_create_date, oligo_modify_date, oligo_disabled_flag +) values (?,?,?,?,?,?,?,?,?,?)"; my $rv = $sth->execute($oligo_id, $project_id, $oligo_type_id, $se +q, $oligo, '52', '52', $create_date, $create_date, '0'); } close $oligo_file;
Your wisdom is greatly appreciated! LomSpace

In reply to How do I improve the effeciency of my script by lomSpace

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.