tame1 has asked for the wisdom of the Perl Monks concerning the following question:

I have a small conundrum (sic?). I have a hash where one of the keys, let's call it 'parents', holds an array of numbers. I want to step through that array, and use the number as a key in another hash, in sequence. I know, I am not making much sense.

Here -
@array = @{$starting_hash->{'parents'}}; # In the end I want $new_hash->{$array[0]}{$array[1]}{$array[2]} and so on . .
The difficulty comes from the fact that I have a few thousand of these arrays, and they come in varying sizes.
The important part is that I need $new_hash to have {key}{key}{key}{key} and so on as deep as the array is long.

I'm just having a mental block on what could do this for me, and thought I would ask for help here.

--J

What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"

Replies are listed 'Best First'.
Re: Positional keys
by japhy (Canon) on Feb 08, 2002 at 15:19 UTC
    Here's a function you might like:
    # multi_dim(\%hash, @keys, $value) # sets $hash{$key[0]}{$key[1]}... = $value sub multi_dim { my $h = \shift; my $v = pop; $h = \$$h->{shift()} while @_; $$h = $v; }

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      japhy,

      If you are female, I smother you with kisses. If you are male, you get one kiss per cheek.

      THANK YOU!

      What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"
Re: Positional keys
by MZSanford (Curate) on Feb 08, 2002 at 15:44 UTC