in reply to Odd number of elements in hash assignment warning. Use of uninitialized value warning
is incorrect. In this context, since %hash is more like an array than a scalar, 'undef' is actually a value you're trying to set to %hash. This "list-ish" behavior lets you do stuff like this:my %hash = undef;
If you're wanting to "un-set" %hash, try either:my %hash = ( key => "value", key2 => "value2" ); # OK my %hash = ( "key", "value", "key2", "value2" ); # OK (same) my %hash = ( "key", "value", "key2" ); # WRONG - gives the + error you describe my %hash = ( undef ); # WRONG - equivalen +t to what you were doing!
But in your code above, this is unnecessary. Simply declaring my %hash; is sufficient, since in Perl this would initialize your hash to be empty.undef %hash; %hash = (); # empty list = empty hash
|
|---|