in reply to List Values As Multidimensional Hash Keys

Seemed to me rather interesting task :)
@a = qw/a b c d e f/; $data = 'K'; $data = { pop @a => $data } while @a; %hash = %$data;

Replies are listed 'Best First'.
Re: Re: List Values As Multidimensional Hash Keys
by Roy Johnson (Monsignor) on Mar 15, 2004 at 20:54 UTC
    Or, building top-down instead of bottom-up:
    $_ = 'a1:a2:a3=foo'; my ($key, $val) = split(/=/); my @keys = split /:/, $key; my %hash; my $href = \%hash; $href = $href->{shift @keys} = (@keys>1) ? {} : $val while @keys; print Dumper(%hash);

    The PerlMonk tr/// Advocate