Re: Unknown level of hash

[email protected] (Luke Palmer)
Newsgroups perl.perl6.language,perl.fwp
Message-ID <[email protected]>
Zhuang Li writes:
> Yes. I think it's both useful and fun. I was thinking something similar
> to
> @hash{@a} = map{1} @a; 
> 
> But getting "$hash->{E1}->{E2}->...->{En} = 1;" instead of "$hash{E1} =
> 1; ... $hash{En} =1;".

Yeah, like this:

    %hash{dims @a} = (1) xx Inf;

> What I'd really like to do is:
> 
> Given @a = ('E1', 'E2', ..., 'En');
> 	@b = ('K1', 'K2', ..., 'Km');
> 	@c = ('V1', 'V2', ..., 'Vm');
> 
> To get the following in one line:
> $hash->{E1}->...->{En}->{K1} = 'V1';
> $hash->{E1}->...->{En}->{K2} = 'V2';
> ....
> $hash->{E1}->...->{En}->{Km} = 'Vm';

    %hash{dims @a}{@b} = @c;

Were you asking the right thing?

Luke
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.