SPUG: spug: Odd number of elements in hash assignment at YYYY
line XX
Pommert, Daniel
Daniel.Pommert at verizonwireless.com
Wed Dec 19 20:04:59 CST 2001
Your problem is the direct assignment from an array (which contains only
keys) to a hash (which contains key/value pairs). Also, I'm unsure what
exactly you were wanting to do. Does "some_pattern" contain a parenthesis?
If so, what should be the key to the hash and what should the value be? Or,
perhaps, did you mean to use grep instead of map?
Your code should either read:
# "some_pattern" has a single parenthesis, which is the desired hash key
@array_x = map m|some_pattern|, at array_y;
%hash = map {($_, 1)} @array_x;
- - O R - -
# You want the key to be the element of array_y and the value to be value
# found in pattern with parenthesis
%hash = map {($_, m|some_pattern})} @array_y;
- - O R - -
# You want only those values that match the pattern and those placed as keys
# in a hash
@array_x = grep m|some_pattern|, at array_y;
%hash = map {($_, 1)} @array_x;
Or, perhaps you ment something else...
Hope this helps,
-- Daniel Pommert
-----Original Message-----
From: Nord, Chris [mailto:chris.nord at attws.com]
Sent: Wednesday, December 19, 2001 5:39 PM
To: 'spug list'
Subject: SPUG: spug: Odd number of elements in hash assignment at YYYY
line XX
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.
Chris Nord
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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