in reply to using other variables as keys to hash

You're trying to use symbolic references (aka "using a variable as a variable name"). This is a very bad idea. Reasons why it is a bad idea are discussed at length by Dominus here, here and here. In fact it's such a bad idea, that had you put use strict in your program (as you always should) you would have got errors with case 2 as well. This is a good thing!

The solution to your problem is to read up about references and complex data structures in Perl. The perlreftut and perldsc manual pages would be a good start.

--
<http://www.dave.org.uk>

Perl Training in the UK <http://www.iterative-software.com>

  • Comment on Re: using other variables as keys to hash