Yes. I think it's both useful and fun. I was thinking something similar
to
@[EMAIL PROTECTED] = 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: fwp@perl.org
> 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
> 
> 


Reply via email to