Loading ...
Sorry, an error occurred while loading the content.

hash error: Odd number of elements

Expand Messages
  • susan59_98
    I am writing a program which gives me an error: Odd number of elements in hash. Why does this happen? What do I have to fix to get rid of the error? Here is
    Message 1 of 2 , Jun 29, 2002
    • 0 Attachment
      I am writing a program which gives me an error: Odd number of
      elements in hash. Why does this happen? What do I have to fix to get
      rid of the error?

      Here is call to the call to teh subroutine.
      #eliminate stuff
      %partSorted = &sortParts($date,@time);

      Here is the subroutine where I create/return the hash:
      ######sub sortParts#######################
      #Eliminate stuff
      sub sortParts{

      ($date,@time) = @_;#stuff arrives in associative array

      .....
      ......
      .....
      .....

      $len = @typeTarget;
      $p = 0;
      #for ease of use, stick sorted parts/types into hash
      #hash doesn't return its key/value in alpha order
      while($p < $len){
      print "path after sort: $pathTarget[$p] type: $typeTarget[$p]\n";

      #put sorted part & type into hash
      #make hash key the path
      #make hash value the type
      $patthTypee{$pathTarget[$p]} = $typeTarget[$p];
      $p++;
      }#end while

      return (\%patthTypee);
      }#end sortParts
    • Jenda Krynicky
      From: susan59_98 ... You are returning a hash reference and trying to assign it to a hash. You have to use either %partSorted =
      Message 2 of 2 , Jul 1, 2002
      • 0 Attachment
        From: "susan59_98" <digregor@...>
        > I am writing a program which gives me an error: Odd number of
        > elements in hash. Why does this happen? What do I have to fix to get
        > rid of the error?
        >
        > Here is call to the call to teh subroutine.
        > #eliminate stuff
        > %partSorted = &sortParts($date,@time);
        >
        > Here is the subroutine where I create/return the hash:
        > ######sub sortParts#######################
        > #Eliminate stuff
        > sub sortParts{
        > ...
        > return (\%patthTypee);
        > }#end sortParts

        You are returning a hash reference and trying to assign it to a hash.
        You have to use either

        %partSorted = sortParts($date,@time);
        and
        return (\%patthTypee);

        or

        %partSorted = %{sortParts($date,@time)};
        and
        return (\%patthTypee);

        or

        %partSorted = sortParts($date,@time);
        and
        return (%patthTypee);

        Jenda
        =========== Jenda@... == http://Jenda.Krynicky.cz ==========
        There is a reason for living. There must be. I've seen it somewhere.
        It's just that in the mess on my table ... and in my brain
        I can't find it.
        --- me
      Your message has been successfully submitted and would be delivered to recipients shortly.