CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Odd number of elements in hash assignment

 



zatlas1
Novice

Jun 29, 2011, 3:07 PM

Post #1 of 3 (782 views)
Odd number of elements in hash assignment Can't Post

Hi all

Here is my code in the 'sub func'

I have two hashes %TransID and %valcod. Both are absolutely fine as hashes. In the end of the subroutine I issue:

$TransID{'hvalcod'} = %valcod;
return %TransID;

In the main program I do:

my %MainTransID = func();
my %Mainvalcod = $MainTransID{'hvalcod'};

and I get 'Odd number of elements in hash assignment at ...' on the second line. What is the reason and how should I correct this without major changes in my code?



Thank you

ZA


miller
User

Jun 29, 2011, 3:10 PM

Post #2 of 3 (780 views)
Re: [zatlas1] Odd number of elements in hash assignment [In reply to] Can't Post

You're trying to assign a hash to a scalar. Instead, assign a hash reference.


Code
$TransID{'hvalcod'} = \%valcod; 
return %TransID;


In the main program:


Code
my %MainTransID = func(); 
my %Mainvalcod = %{$MainTransID{'hvalcod'}};


- Miller


zatlas1
Novice

Jun 29, 2011, 3:22 PM

Post #3 of 3 (779 views)
Re: [miller] Odd number of elements in hash assignment [In reply to] Can't Post

Hi Miller

Thank you

It works like a charm... and I understand why! I tried to return a reference but I missed that part of the syntax %{$MainTransID{'hvalcod'}} to derefernce it

ZA

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives