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

I am running a program and I am receiving the following error: "Odd number of elements in hash assignment at line 16" I am stumped as to what this means, I have tried the Camel book to no avail and I could use a little help. Could this be caused by the program thinking I was passing/referencing a hash when I wanted to pass/reference an array?

Replies are listed 'Best First'.
Re: Can someone explain this error?
by merlyn (Sage) on May 22, 2001 at 01:05 UTC
    If you have an error message, please tell Perl to RTFM for you. Add -Mdiagnostics to your command line.
    $ perl -Mdiagnostics -e '%foo = 3' ... Odd number of elements in hash assignment at -e line 1 (#2) (S) You specified an odd number of elements to initialize a hash, +which is odd, because hashes come in key/value pairs. $

    -- Randal L. Schwartz, Perl hacker

Re: Can someone explain this error?
by arturo (Vicar) on May 22, 2001 at 01:06 UTC

    As well as the call to show us the code, let me let you in on perldoc perldiag and even better, the use diagnostics pragma. Both will help explain what error messages mean, and often enough suggest a fix.

    A common enough mistake is

    my %hash = { foo => 'bar', baz=> 'bletch'};

    Those curlies {} should be parens ().

    HTH

Re: Can someone explain this error?
by how do i know if the string is regular expression (Initiate) on May 22, 2001 at 01:07 UTC
    As physi said, you should post your code to help us help you.

    But I'll help you anyway.

    my %hash = ( 1 , 2 , 3 );
    If you're using #!/usr/bin/perl -w then you will the warning (not error) that you are asking about. It's basically saying that you are not giving a value for $hash{3}, so it will be undefined.

    -FrankG

Re: Can someone explain this error?
by physi (Friar) on May 22, 2001 at 01:02 UTC
    Please let us see the code, it's much easier to help then ...

    Cheers

    ----------------------------------- --the good, the bad and the physi-- -----------------------------------
      Here is where I think the prob is:
      @key_array = keys %pers_dcr_files; my(@graphic) = (); my(@url) = (); for ($i=0; $i<2; $i++) { $key = $key_array[$i]; $graphic[$i] = $pers_dcr_files{$key}{SmallGraphic}; $url[$i] = $pers_dcr_files{$key}{LinkURL}; if (("$graphic[$i]" ne "") && ("$url[$i]" eq "")) { $name = generate_link_name($pers_dcr_files{$key}{RightNavL +aunchDate}, $pers_dcr_files{$key}{RightNavExpirationDate}, 'p', $pers +_dcr_files{$key}{PromotionName}); $url[$i] = generate_url_path($name); } }
      This basically trying to take the first two keys out of a hash and pass a few of the values from the specified key into another routine. I can include the two routines that are called as well if you would like.

        Which is line 16?