Hello Again.New to Perl. Geting There.

I have this script that will read a Table. The table has 2 fields: Draw date (Primary Key), Draw Number (an Index). The table is MYSql in MYISAM format.

I copied the script below from a book to get the database to open then read the table. If I understand correctly, gthis script reads the entire table into memory then extracts thae rows based on fetchrow.

We come from the MicroFocus Icobol platform that uses similar isam files. How would you just Read one record at a time (by either primary key or the other index) without storing them all in memory, do what you have to do with it, then read the next record?

# Connect To The Database my $dbh = DBI->connect("DBI:mysql:masslottery_db", "root", "system1"); die "Connect to masslottery_db failed: " . DBI->errstr() unless $dbh; print "connect to masslottery_db successful!\n"; #Prepare The Query To Get Data From Table Dailymf #$dbh Is Called The Database Handler my $sth = $dbh->prepare("Select dailymf_drawdate,dailymf_number FROM d +ailymf") or die "Prepare For Dailymf Failed: " . $dbh->errstr( +); #Execute The Query #$sth Is Called The State Handler $sth->execute() or die "Execute For Dailymf Failed: " . $sth->errstr(); #Read (loop) Each Row (record) and Print It while (($dailymf_drawdate, $dailymf_number) = $sth->fetchrow()) { print "$dailymf_drawdate : $dailymf_number\n"; }

Thanks again for the help.


In reply to Reading A TAble by PerceptiveJohn

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.