Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Allow me to explain.

fetchall_arrayref returns an array ref, i.e. a scalar value which is a reference to an array (which will stringify as something like ARRAY(0x81503e8) if you try and print it out). You want to dereference this, and gain access to the array, hence the @{...}. This array has one element per row.

Unfortunately, this is not quite exactly what you want, as it's an array of arrayrefs. Each of the referenced arrays only has one element, as your SQL is only returning one column, but would contain more than one value if your query was returning more columns (note: there is no such method as fetchcol_arrayref).

The trick I have done is to fish out the element of each array, as the action for the map function. I could have written this as a for loop, but this kind of inline transformation lends itself to the builtins map and grep.

For further reading, see perlreftut.

--
wetware hacker
(Qualified NLP Practitioner and Hypnotherapist)


In reply to Re^3: Populating an array from a mysql select by rinceWind
in thread Populating an array from a mysql select by Nik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-03-29 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found