in reply to Hash Push

here ya go: a recursive routine that returns a hash ref. where the values associated with each key are arrays (actually, references to arrays)

use strict; use Data::Dumper; sub Recurse { my $n = shift || 0; if ($n <= 0) { return {}; } else { my $val = [ map { $n ** $_ } (1 .. 5) ]; return { $n => $val, %{Recurse(--$n)} }; } } my $powers = Recurse(5); print Dumper($powers);
outputs:
$VAR1 = { '1' => [ '1', '1', '1', '1', '1' ], '2' => [ '2', '4', '8', '16', '32' ], '3' => [ '3', '9', '27', '81', '243' ], '4' => [ '4', '16', '64', '256', '1024' ], '5' => [ '5', '25', '125', '625', '3125' ] };

Replies are listed 'Best First'.
RE: Re: Hash Push
by Adam (Vicar) on Aug 16, 2000 at 02:32 UTC
    There is some good code there, but it has a fatal flaw. It doesn't merge keys together. Perhaps that's my fault, I didn't point that part out. The reason the values are arrays (er, references to arrays... ) is so that the various values associated with a key can be collected (in order of collection even... hehe)

    You see?

      i'm not sure this is very easy to understand in simplified form. maybe you should post a new SOPW with more complete code.