As a side note, you may want to also lookinto the DBI::fetchrow_arrayref() whereas having DBI return a reference to an array rather than a copy of the extraced array has tended to be faster. You can think of it in the light of having DBI return a pointer to the particular segment of memory where the data is rather than returning all the data in memory.

The only change you would have to make, in this example (rather than re-naming the method call) would be to de-reference the array reference as you are looking to use the values within it. Therefore you could:
# Assuming you like the idea of scoping two variables # lexically within the while block as noted in previous # comments while ( my ( $page_title, $hit_count ) = @{ $cursor->fetchrow_arrayref +() } ) { $page_hits{$page_title} = $hit_count; }
You will see that the supplimental change to the logic would be the addition of the @{} block, telling Perl to de-reference the array reference returned from fetchrow_arrayref

Not a big deal, in most (some) cases, but certainly something to think about.

print map{chr}(45,45,104,97,124,124,116,97,45,45);
... and I probably posted this while I was at work => whitepages.com | inc.

In reply to Re: Basic Array Question by wazzuteke
in thread Basic Array Question by pickledegg

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.