Dear Monks, I have an interesting problem and wondered whether anyone has come across this before.

I am using the DBI module to simply read a mysql database table and store columns into seperate arrays. The columns are storing identification codes. However, when i print the arrays within my perl script, one value has been missed out and placed later on in the array (which obviously messes the order of things up ;-( ).

The id that has been mis-placed (M57165208) looks out of place (as, although is contains chars and numbers, it is numerically higher that those before and after it). Can anyone suggest what is going on here and/ or an alternative solution that will preserve the database order within the per script?

Here is my code and a sample of the id's:

my $sth21= $dbh->prepare(qq{SELECT MR_M FROM MR2}); die "Couldn't prepare queries; aborting" unless defined $sth21; $sth21->execute(); while (my @ary=$sth21->fetchrow_array()) { push @mr_m, @ary; } my $sth22= $dbh->prepare(qq{SELECT MR_R FROM MR2}); die "Couldn't prepare queries; aborting" unless defined $sth22; $sth22->execute(); while (my @ary=$sth22->fetchrow_array()) { push @mr_r, @ary; } # HERE I PRINT OUT WHAT I HAVE READ FROM THE DATABASE for (my $i=0; $i<@mr_m; $i++) { print "$mr_m[$i]\t $mr_r[$i]\n"; }
This is a sample of numbers from the database:
mysql> select * from MR2 limit 10; +-----------+--------+ | MR_M | MR_R | +-----------+--------+ | M13470333 | RL2591 | | M13470334 | RL2590 | | M13470335 | RL2588 | | M13470339 | RL4708 | | M13470341 | RL2584 | | M13470342 | RL2583 | | M57165208 | RL2582 | | M13470344 | RL2580 | | M13470345 | RL2579 | | M13470346 | RL2578 | +-----------+--------+ 10 rows in set (0.00 sec)
This is how they look when printed out:
M13470333 RL2591 M13470334 RL2590 M13470335 RL2588 M13470339 RL4708 M13470341 RL2584 M13470342 RL2583 M13470344 RL2582 M13470345 RL2580 M13470346 RL2579 M13470347 RL2578

In reply to DBI fetchrow_array problems by Anonymous Monk

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.