in reply to Re: Hash assignment "odd" ness
in thread Hash assignment "odd" ness

Thank you!

"list" was my disconnect. I tried the direct assignment construct multiple times, before I tried building the string and, every time Dumper out put would look like:

$VAR1 = 'Comments'; $VAR2 = ''; $VAR3 = 'InstallAddID'; $VAR4 = ''; . . .

When what I was expecting was:

Comments = ''; InstallAddID = '';

So the "X" is "%hash = ($never_gonna_work)" and the "Y" is "Why doesn't Dumper read my mind."

print Dumper(\$po); would have solved my problem.<\p>

Thanks again for the clarity. And this now works.

#!/usr/bin/perl use strict; use warnings; use diagnostics; use Data::Dumper; use DBI; my $dbargs = {AutoCommit => 0,PrintError => 1}; my $dbc = DBI->connect("dbi:SQLite:dbname=da_hrb.db","","",$dbargs); # get the default po my $sth = $dbc->prepare('select * from der_po where poid = 0'); $sth->execute; my $po = $sth->fetchrow_hashref; # corrected. thanks ikegami print Dumper($po);

Replies are listed 'Best First'.
Re^3: Hash assignment "odd" ness
by ikegami (Patriarch) on Jun 30, 2010 at 06:41 UTC
    Dumper takes a list of scalars for input. If you want to dump a hash, you need to pass a reference to the hash.
    print Dumper(%hash); # Dumps the result of evaluating the hash. Meh. print Dumper(\%hash); # Dumps the ref and the referenced hash. Good.

    On the other hand, $po is a scalar. No need to pass a reference to it.

    print Dumper(\$po); # Why?? print Dumper($po); # Good.
      print Dumper(\$po);  # Why??

      I wanted to be doubly sure!

      Truly, it was an artifact from a "print Dumper(\%hash);" test.

      It has been corrected.