in reply to hash problem

I'm sure I saw this done without the temp var $x once?

my @a = qw[ one two three ]; my $x = 1; $hash = {}, $hash->{ $_ } = $x, $x = $hash for reverse @a; print Dumper $hash; $VAR1 = { 'one' => { 'two' => { 'three' => 1 } } };

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

Replies are listed 'Best First'.
Re^2: hash problem
by dave_the_m (Monsignor) on Jul 09, 2004 at 20:47 UTC
    Without $x:
    my @keys = qw(one two three); my $hash = 1; $hash = { $_=> $hash } for reverse @keys;
    Of course this fails if @keys is empty

    Dave.

      That's the one :)


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon