RE: Unknown level of hash

[email protected] ("Zhuang Li")
Newsgroups perl.perl6.language,perl.fwp
Message-ID <7A7034183C845E4B9963F65505BA34D121939C@vchqex01.wl.corp.valueclick.com>
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';

john

> -----Original Message-----
> From: Jeff Yoak [mailto:[email protected]]
> Sent: Monday, March 28, 2005 3:40 PM
> To: Zhuang Li
> Cc: [email protected]
> Subject: Re: Unknown level of hash
> 
> On Mon, 2005-03-28 at 15:06, Zhuang Li wrote:
> > Hi, given an array: @a = ('E1', 'E2', ..., 'En');
> >
> >
> >
> > Is there an easy way, hopefully one liner, to do the following
without a
> > loop? If not, will Perl support this in Perl 6?
> >
> >
> >
> > $hash->{E1}->{E2}->...->{En} = 1;
> 
> use Data::Dumper;
> 
> my @x = qw/a b c d e/;
> my $h = {};
> my $s = join '}->{',@x;
> eval '$h->{'.$s.'}=1';
> 
> print Dumper $h;
> 
> 
> You asked this on a "fun with Perl" mailing list, but something about
> your tone implies that you think this may be a useful, good thing to
do
> rather than simply fun.  Please know that I intend this only for fun.
> :-)
> 
> Cheers,
> Jeff
> 
>
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.