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

At the beginning of my script, I have declared the following:
my %Questions = (); my @Sorter = ();
Then a little further down, I send them to a subroutine as references:
(%Questions,@Sorter) = Load(\%Questions,\@Sorter,$max,$data);
That is where I receive the error of odd number of elements in my hash assignement.
I have looked through the Camel book and perlref, but haven't gained any insight into this.
Any and all suggestions would be welcomed.

TStanley
In the end, there can be only one!

Replies are listed 'Best First'.
Re: Odd number of elements in hash assignment
by chipmunk (Parson) on Mar 24, 2001 at 01:37 UTC
    Are you really trying to assign to %Questions and @Sorter at the same time? How is Perl supposed to know where in the list the values for %Questions leave off and the values for @Sorter begin?

    Perl can't know, so all the values go into %Questions. You'll have to rethink how your Load function returns its results.

    This is mentioned in perldata, under List Value Constructors.

    The final element may be an array or a hash: ($a, $b, @rest) = split; my($a, $b, %rest) = @_; You can actually put an array or hash anywhere in the list, but the first one in the list will soak up all the values, and anything after it will get a null value. This may be useful in a local() or my().
Re: Odd number of elements in hash assignment
by TStanley (Canon) on Mar 24, 2001 at 02:04 UTC
    After some thought, I added the following declarations:
    my $refQuestions = \%Questions; my $refSorter = \@Sorter;
    and changed the call to the function as follows:
    ($refQuestions,$refSorter) = Load(\%Questions,\@Sorter,$max,$data);
    And all was well..

    TStanley
    In the end, there can be only one!