Your DBI stuff is fine. Your problem is your reference syntax. Try this:

while($info = $sth->fetchrow_hashref) { for (keys %$info) { print "$_ => $$info{$_}\n"; } }

You can also use %{$info} instead of %$info, but IMO that syntax is noisier and usually unnecessary. (Sometimes you have to use it, for example when you are interpolating and the variable is directly followed by word characters that would otherwise be taken for part of the variable name.)

The syntax you use, %{info}, is exactly the same as saying %info -- that is to say, it doesn't dereference $info, but refers to a completely separate variable instead, a hash variable called %info. You want either %{$info} or %$info.

You may also occasionally see an arrow syntax, like $info->{key} = $value, but for now you don't need to worry about that. Just know that when you do see it, it's a dereferencing syntax.

The reason for the %{info} syntax is so that 'info' can be replaced with an arbitrary expression. For example, under no strict refs you could say %{"in" . "fo"} and it would still refer to %{info}. It does not however refer to the same thing as %{$info}.


;$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$;[-1]->();print

In reply to Re: DBI Fetchrow_hasref issue by jonadab
in thread DBI fetchrow_hashref issue by jorvic

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.