Hail wise ones.

I am trying to populate a hash with a generated (%pohash = ($tmp);)string.

No matter what I try I keep getting following error:

"Odd number of elements in hash assignment at ./test.pl line 27 (#1)"

And the hash then only contains 2 key/values.

I have read many other posts and reviewed Hash, Hashref and quoting. I have even dusted off
the llama ("Learning Perl").I can kinda sorta see what is wrong, the assignment string is breaking
into $VAR1 and $VAR2, but I can not seem to solve the problem.

Thank you all in advance.

Code and Output Follows: #!/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_db.db","","",$dbargs); # get the default po my $sth = $dbc->prepare('select * from der_pos where poid = '0'); $sth->execute; my $po = $sth->fetchrow_hashref; my $tmp = ''; # build a string and add some commas while ( my ($key, $value) = each(%$po)) { if ($tmp) { $tmp = $tmp . ' , ';} $tmp = $tmp . "$key => " . (($value) ? qq("$value") : q("a +")); } #print $tmp . "\n"; my %pohash = (); %hash = ($tmp); print Dumper(%pohash); Output Follows: Odd number of elements in hash assignment at ./test.pl line 25 (#1) (W misc) You specified an odd number of elements to initialize a h +ash, which is odd, because hashes come in key/value pairs. $VAR1 = 'Comments => "a" , InstallAddID => "a" , County => "a" , Ariba +ToID => "a" , AribaFromID => "a" , ProcessStatus => "a" , DeliverToAd +dID => "a" , HasBadPart => "a" , ShipToCode => "a" , AribaPO => "Defa +ult" , DeptidCode => "a" , OrderType => "a" , PODateProcessed => "201 +0-06-29 10:53:25" , PODate => "a" , ShippingNotes => "a" , Requisitio +nNum => "a" , Mode => "a" , StoreNumber => "a" , Replaced => "a" , Ta +rget => "all" , OrderNotes => "a" , ReqDeliveryDate => "2010-06-29 10 +:53:25" , Iteration => "a" , LineItemCount => "a" , POID => "a" , Jam +coPO => "a" , DebugData => "a" , POTotal => "a"'; $VAR2 = undef; Issuing rollback() due to DESTROY without explicit disconnect() of DBD +::SQLite::db handle dbname=/da_db.db.

In reply to Hash assignment "odd" ness by phigment

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.