SPUG: spug: Odd number of elements in hash assignment at YYYY line XX

Yitzchak Scott-Thoennes sthoenna at efn.org
Wed Dec 19 21:40:37 CST 2001


In article <F3575E1A061BD411828C00508B94E1A60825C8ED at WA-MSG04>,
"Nord, Chris" <chris.nord at attws.com> wrote:
>Question on the below code.  I get a PERL message, "Odd number of elements
>in hash assignment at nlerg line XX".  The results of the map get populated
>as keys in %hash.  Why the "Odd number..." error?
>
> @array_x = map m|some_pattern|, at array_y;
> %hash = @array_x;
>
> foreach (keys %hash){
>  print "$_\n";
> }
>
>Odd number of elements in hash assignment at nlerg line XX
>line XX is %hash = @array_x;
>
>Also tried $hash{map m|some_pattern|, at array_y} = ''; but the results of the
>map do not generate a key list in the hash.

You almost got it.  Try:

@array_x = map m|some_pattern|, at array_y;  # I assume some_pattern has () in it
@hash{@array_x} = ('')x @array_x;

(or just @hash{@array_x} = () to leave all the values undefined).

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/





More information about the spug-list mailing list