Most repsected monks,

Using DBI and MySQL on W32 in an app using Tk.

I have two arrays:

  • @fields which has in it a number of fields read from a flat text file database
  • @map_fields which is the names of the fields in the database that the field data is to be stored in.
  • The two arrays are returned by a sub that allows the user to select an available field from the database for each field of the import.

    The number of fields in the import can vary! The input db's can have as few as 5 or as many as 30 fields and the order of the fields varies also.

    In the past I wrote a thing like this for one particular flat-file layout, I parsed the fields directly into a hash using split:

    sub Read_leads { open (INPUT, "<$lo_in") || die "Cannot open source file $!\n"; while (<INPUT>) { $in_ln = $_; $in_ln =~ s/^\s+//; $in_ln =~ s/\s+$//; ($lead{Email}, $lead{FirstName}, $lead{LastName} , $lead{DOB}, + $lead{Gender}, $lead{Country}, $lead{State}, $lead{ZIP}, $lead{Addre +ss}, $lead{City}) = split(/,/, $in_ln); $lead{DATE} = $indate; if ($lead{Email}) { $lead{Datasource} = '10222'; $rec = {}; while (($k, $v) = each %lead) { $v = $dbh->quote( $v); $rec->{$k} = $v; } push @leadslist, $rec; } %lead = (); } return; }
    Then after a couple of other simple operations I took the array of hashes and stored it like this:
    sub Write_leads { @fields = qw(Email FirstName LastName Address City State ZIP Datas +ource AdType OrigIP DATE Gender DOB phone Country); $sth = $dbh->prepare("INSERT INTO $leads_tbl VALUES (?,?,?,?,?,?,? +,?,?,?,?,?,?,?,?)"); for $href (@leadslist) { $sth->execute( @{$href}{@fields}); } return; }
    But how big can the array of hashes get? OK, I can do the import line by line and play it safe, thats no problem.

    But how do I handle the variable nature of what I am trying to do now?

    Many thanks in anticipation!

    John


    In reply to DBI and two arrays question! by jdtoronto

    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.