user2503871
user2503871

Reputation: 27

Getting an "Odd number of elements in hash assignment" error

I'm getting the following error when running a Perl script

Odd number of elements in hash assignment at GenerateInterchangeFromIntegrationManifest.pl line 197.  
{  
    "Change list" : "0"  
}

This is the script:

my %labelFieldMap = (IUItemName => convertIuItemName,
                      Changelist => sub {},
                     IUItemLevel => createNormalConvert('iuItemLevel'),
                     ContactPOC => \&convertContacts,
                     Cspec => \&convertCspec,
                     IsNew => createBooleanConvert('isNew'),
                     Submitter => createNormalConvert('submitter'),
                     LabelType => createNormalConvert('type'),
                     Revision => createNestedConvert('component', 'revision'),
                     RevisionName => sub {},
                     ComponentBaseName => createNestedConvert('component', 'baseName'),
                     Version => createNestedConvert('component', 'version'),
                     PLMapping => createNormalConvert('plMapping'),
                     BidMapping => createNormalConvert('bidMapping'),
                     ClientId => createNormalConvert('clientId'),
                     Path => \&convertPath,
                     ExtendedData => \&convertExtendedData);

Can any one help me resolve this issue?

Upvotes: 0

Views: 1450

Answers (1)

Neil Slater
Neil Slater

Reputation: 27207

There are several subroutine calls in assignment to the hash that could be returning lists with an even number of elements (which would make the list count odd overall, and also change which data is keys and which values from that point in the list on, which is probably worse for you). As Dallaylaen has pointed out in comments, this could simply be a line which returns "nothing", return; which will evaluate to empty list (), i.e. an even length of 0, in list context. All the subroutine calls in the question code will be evaluated in list context.

I would suggest a simple debug technique:

  • Comment out all the lines with a function call, that should remove the warning.
  • Then add back a few at a time and re-test.
  • When the warning re-appears, you will have isolated the problem to one of a few subroutines.
  • Repeat until you know which one.
  • Then investigate that call to see how you might fix it.

Upvotes: 5

Related Questions