Basically I'm trying to print the column headers from a db query. I can iterate through each row and using printf I can print out the data, but it doesn't work when I'm trying to print out the column headers.

eg:

@row = $sth->fetchrow_array(); printf "%15s %12s %12s %12s %9s %5s $5s", @row;
- produces a formated line of data from the database

But this same approach applied to the column headers prints only ARRAY(0x168218):

@fieldNames = $sth->{NAME_uc}; printf "%15s %12s %12s %22s %9s %5s $5s", @fieldNames;
It doesn't much seem to matter if I replace @fieldNames with $sth->{NAME_uc} or @$fieldNames, I still don't get the array interpreted as a list, despite the fact that this appears to be the same methodology used to display the row data.

What hoops am I supposed to be jumping through here? Iterating through the column name array is a poor option because then I'd have to manually format the whole thing which seems a huge waste of code.


In reply to printing an array reference by gryf

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.