Do you know where your variables are? | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
You appear to be very confused! my $maxBits=60 is not a hash reference. 60 is a plain old scalar. my %maxBits=60 is indeed wrong, because %maxBits is a hash, but 60 is again as plain old scalar. Perl will *try* to Do The Right Thing and assume that the right hand side is a list of key/value pairs, but it can't because there's an odd number of elements in the list (it gets treated as a list with one element). Hence the warning "Odd number of elements in hash assignment". It then, after warning you, extends the list by appending an undef, creating a hash that looks like this:
that is, the hash has a single key in it (60) whose value is undef. Finally, %maxBits=map {$_=>60};. This is a syntax error, because map needs a list of values to work with. I recommend that you stop and read Learning Perl (the Llama book). IIRC (and I admit I've not looked at it in the last several years) it includes a good tutorial on data types - scalars, arrays, hashes. I don't think it includes much on references, but once you've read and understood the Llama you should be able to cope with perlreftut, perldsc, and all the other tutorials that come with perl and, if you still need it, the documentation for the map function. In reply to Re: initialize all values in a hash
by DrHyde
|
|