phigment has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hash assignment "odd" ness
by kennethk (Abbot) on Jun 29, 2010 at 19:24 UTC | |
by phigment (Initiate) on Jun 30, 2010 at 06:27 UTC | |
by ikegami (Patriarch) on Jun 30, 2010 at 06:41 UTC | |
by phigment (Initiate) on Jun 30, 2010 at 07:23 UTC | |
|
Re: Hash assignment "odd" ness
by Corion (Patriarch) on Jun 29, 2010 at 19:30 UTC | |
|
Re: Hash assignment "odd" ness
by ssandv (Hermit) on Jun 29, 2010 at 19:35 UTC | |
|
Re: Hash assignment "odd" ness
by Argel (Prior) on Jun 30, 2010 at 19:44 UTC |