I just wanted to follow up and explain _why_ your code doesn't work the way you expect and why it is necessary to use the notation shown by
Tortue,
Ovid, and
lachoy above.
push @$somehash{$foo.$bar}, $x;
# is the same as
push @{$somehash}{$foo.$bar}, $x;
Perl sees
$somehash as a scalar holding a reference to a hash. Paraphrasing from the
Panther, when parsing an expression like this, key lookups are done last. Since the hashref is dereferenced before the key lookups are done, the
@ is applied to return a hash slice.
(aside: With a regular hash
%somehash, a one-element hash slice (which is usually not what you want) would look like
@somehash{$foo}, but with a scalar
$somehash as a hashref, you would use
@$somehash{$foo} or
@{$somehash}{$foo} as above.)
But you didn't want a hash slice-- you wanted to dereference an array reference. In order to do that, you put braces around the scalar holding the array ref. Now we have
@{ $somehash{$foo.$bar} }, which is the notation shown by
the other monks earlier in this thread. The outer braces force the hash lookup to be done before the
@ is applied to dereference the returned value (which, of course, is an array ref). I hope this helps explain what was happening in your code. Also, for a good reference on, well, references, check
tye's excellent
references quick reference (Re: push).
--
sacked