pglenski has asked for the wisdom of the Perl Monks concerning the following question:

I get his warning: Reference found where even-sized list expected at enf1.pl line 6. At line 6 I have this:
%rims = { GROUP=>$string, LNAME=>$string, INITS=>$string, MBRID=>$string, M_DOB=>$string, DEPCD=>$string, P_FNAME=>$string, P_DOB=>$string, P_SEX=>$string, };
Then I have this code:
while(<IN>) { chomp; @tmp=split(/,/,$_); $key = $tmp[0] . $tmp[6]; $rims{$key} = {GROUP=>$tmp[1],LNAME=>$tmp[2],INITS=>$tmp[3], MBRID=>$tmp[4],M_DOB=>$tmp[5],DEPCD=>$tmp[6], P_FNAME=>$tmp[7],P_DOB=>$tmp[8],P_SEX=>$tmp[9],}; }

Replies are listed 'Best First'.
Re: data stuctures
by socketdave (Curate) on Sep 23, 2005 at 16:41 UTC
    Replace the {} in your hash definition with ()... If you wanted a hashref, you would use {}, but assign to a scalar:
    $rims = { GROUP=>$string, LNAME=>$string, INITS=>$string, MBRID=>$string, M_DOB=>$string, DEPCD=>$string, P_FNAME=>$string, P_DOB=>$string, P_SEX=>$string, };
    update:
    Thanks to ikegami for pointing out the bigger problem with your code. The change I suggested will definitely fix your warning but will definitely not make your code do what you expect.
Re: data stuctures
by ikegami (Patriarch) on Sep 23, 2005 at 17:04 UTC
    While what socketdave said is true, I'm not sure why you have line 6 at all. That whole initialisation isn't consistent with %rims's use in the second snippet. You'll end up with something like the following. Why are keys and records at the same level?
    ( GROUP => ..., LNAME => ..., INITS => ..., MBRID => ..., M_DOB => ..., DEPCD => ..., P_FNAME => ..., P_DOB => ..., P_SEX => ..., key1 => { GROUP => ..., LNAME => ..., INITS => ..., MBRID => ..., M_DOB => ..., DEPCD => ..., P_FNAME => ..., P_DOB => ..., P_SEX => ..., }, key2 => { GROUP => ..., LNAME => ..., INITS => ..., MBRID => ..., M_DOB => ..., DEPCD => ..., P_FNAME => ..., P_DOB => ..., P_SEX => ..., }, ... );