Responding to your update: you need to read the DBI man page more carefully ("perldoc DBI"). And/or you need to be more attentive to the "sigils" that you attach to your variable names ("@" for arrays, "%" for hashes, "$" for scalar variables or for a single indexed element within an array or hash).

Here's a relevant snippet from the man page about "fetchrow_array":

If called in a scalar context for a statement handle that has more than one column, it is undefined whether the driver will return the value of the first column or the last. So don't do that. Also, in a scalar context, an "undef" is returned if there are no more rows or if an error occurred. That "undef" can't be distinguished from an "undef" returned because the first field value was NULL. For these reasons you should exercise some caution if you use "fetchrow_array" in a scalar context.

Now, it does seem like your query will return a single value per row, so maybe  while ( my $market = $sth->fetchrow_array ) should work the way you expect. But maybe you shouldn't count on that.

It would suffice to use parens in the assignment, so that everybody is clear that fetchrow_array is being called in a list context:

while ( my ( $market ) = $market_sth->fetchrow_array ) { ... }
The fact that you can get it to work in a scalar context at all is probably not important (except to the extent that this reveals bugs or inconsistencies in your particular DBD module). It's just better not to do it that way.

In reply to Re: Mysterious Code "DBI" - Why is this working? by graff
in thread Mysterious Code "DBI" - Why is this working? by awohld

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.