Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

# Re: Unknown level of hash

1 view

### Markus Laire

Mar 29, 2005, 8:33:05 AM3/29/05
to Zhuang Li, perl6-l...@perl.org, f...@perl.org
Zhuang Li wrote:
> 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;".
>
> 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';
>

I'll attempt a quess based on S03 & S04 & S09.
( http://dev.perl.org/perl6/synopsis/ )

S09 says that @nums[dims 0..2] means @nums[0;1;2]
S09 also says that "Everything we've said for arrays applies to hashes
as well ..."
S04 tells how to process several lists in parallel in for-loop.
S03 tells about unary * list-flattening op.

for @b ¥ @c -> \$b, \$c { \$hash->{dims (*@a,\$b)} = \$c }

ps. I'm not 100% sure if I got that (*@a,\$b) right. I want to add \$b to
@a and feed it to dims as one list.

--
Markus Laire
<Jam. 1:5-6>

### Luke Palmer

Mar 29, 2005, 8:43:17 AM3/29/05
to Zhuang Li, Jeff Yoak, f...@perl.org, perl6-l...@perl.org
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

0 new messages