in reply to Creating a hash with the same name as the value of $hashref-{y}

Do you really need to do this? You would not be using strict and you would be using symbolic references if you actually do this. Can't you just create a master hash of hashes, and have the keys be the value your talking about?
my %master; $master{$hashref->{y}}{$hashref->{z}} = 'value'; # In the spirit of giving 'em enough rope, # and hoping I never have to maintain the code, # here's the symbolic reference version ${$$hashref{y}}->{$$hashref{z}} = 'value';
  • Comment on Re: Creating a hash with the same name as the value of $hashref-{y}
  • Download Code

Replies are listed 'Best First'.
Re: Re: Creating a hash with the same name as the value of $hashref-{y}
by kingman (Scribe) on Aug 15, 2001 at 23:29 UTC
    The trouble is the values are coming from user input so I can't create a hash of hashes :(
      The trouble is the values are coming from user input so I can't create a hash of hashes.

      How is that a valid reason? Please don't use symbolic references without a good reason. Processing user input is an ever better reason NOT to use symbolic references. What if you end up trashing a perlvar? Create a HoH and don't live dangerously, here's a snippet that processes input:

      my %HoH; while (<DATA>) { my ($name, $key, $value) = split; $HoH{$name}{$key} = $value; } __DATA__ name key value a b c 1 2 3