in reply to Re: Strange Hash Problem
in thread Strange Hash Problem
I thought you could assign a value to the hash likeYou can, but you probably shouldn't. The first example puts sometext (which you needn't double-quote, since you aren't interpolating) into the key SO (which you needn't quote at all, since hash keys auto-quote) of the anonymous hash that lives at key 101010 of %vhash. That is, this is the same asand then go on and assign an level of hash$vHash{"101010"}{"S0"} = "sometext";$vHash{"101010USED"}{"S0"}{"SYSTEM"} = "sometext";
The second assignment treats${ $vHash{101010} }{S0} = 'sometext';
While there's no need for the entries of a hash to be homogeneous—it's perfectly OK if some entries are hashes, some are hashes-of-hashes, and so on—it'll probably lead to confusion unless you really mean it.ref $vHash{101010}; # => 'HASH' ref $vHash{101010}{S0}; # => undef ref $vHash{101010USED}; # => 'HASH' ref $vHash{101010USED}{S0}; # => 'HASH'
UPDATE: As ikegami points out, one of the ways that it can confuse is that you can wind up treating a simple scalar as a (symbolic) hash reference, with the sort of unexpected results that you've discovered.
|
|---|