in reply to Re^2: How to get specific hash elements?
in thread How to get specific hash elements?

Ah. Well, clearly, all the values of the "leaf" nodes in the structure are undef. What you want is the keys of the bottom level of the struct. E.g.:

my @values = keys %{ $hash{'test1'}{'fixed name'} };
A word spoken in Mind will reach its own level, in the objective world, by its own weight

Replies are listed 'Best First'.
Re^4: How to get specific hash elements?
by talking_walnut (Initiate) on May 14, 2007 at 16:16 UTC
    But is it possible to have a scalar for each "fixed_name" assigned the value of "value"? I suppose a better representation of the hash would be:
    $VAR1 = 'random_name '; $VAR2 = { 'Fixed_name1 ' => { 'value ' => undef }, 'Fixed_name2 ' => { 'value ' => undef } }; $VAR3 = 'random_Name '; $VAR4 = { 'Fixed_name1 ' => { 'value ' => undef }, 'Fixed_name2 ' => { 'value ' => undef } };
    The fixed names are always going to be the same but there will be hundreds of random names. I want to return the value of the fixed name to another function that will display this value on a webpage for each random name. There will only ever be 1 element for value. I hope I'm explaining this better each time and not just making it twice as confusing :-)
      It sounds like you just want your structure to be like
      $VAR2 = { 'Fixed_name1 ' => 'value ', 'Fixed_name2 ' => 'value ' };
      Then your original code would do what you expect. So assign just the value, rather than a hashref that uses the value as a key.

      Caution: Contents may have been coded under pressure.