On Mon, Mar 28, 2005 at 03:06:41PM -0800, 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;
If you're feeling f
On Mon, 2005-03-28 at 18:43, Uri Guttman wrote:
> > "ZL" == Zhuang Li <[EMAIL PROTECTED]> writes:
>
> ZL> Hi, given an array: @a = ('E1', 'E2', ..., 'En');
> ZL> Is there an easy way, hopefully one liner, to do the following without a
> ZL> loop? If not, will Perl support this in Perl 6
On Tue, Mar 29, 2005 at 05:50:18AM +, Ton Hospel wrote:
> I always found the code to do this WITH a loop quite funny in fact:
>
> my $work = \$hash;
> $work = \$$work->{$_} for @a;
> $$work = 1;
Ha ha ha :)
On Mon, Mar 28, 2005 at 03:06:41PM -0800, 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;
To read from such a se
I always found the code to do this WITH a loop quite funny in fact:
my $work = \$hash;
$work = \$$work->{$_} for @a;
$$work = 1;
> "AS" == Aaron Sherman <[EMAIL PROTECTED]> writes:
AS> On Mon, 2005-03-28 at 18:43, Uri Guttman wrote:
>> > "ZL" == Zhuang Li <[EMAIL PROTECTED]> writes:
>>
ZL> Hi, given an array: @a = ('E1', 'E2', ..., 'En');
ZL> Is there an easy way, hopefully one liner, to do the following
Hey all...
Vladi Belperchinov-Shabanski wrote:
[snip...]
and 'hidden loop' one:
@a = ( 'E1', 'E2', 'E3', 'En' );
$a = 1;
map{ $a = { $_ => $a } } reverse @a;
print Dumper( $a );
The problem with this one is that by doing this you destroy existing
hashes. e.g. :
@a = ( 'E1', '
Vladi,
I like the 'hidden loop' with map solution better. As you can probably
tell, just get:
$hash->{E1}->{E2}->...->{En} = 'v1' is not that meaningful but this is:
Given:
$a = [
['E11', 'E12', ..., 'E1n'],
['E21', 'E22', ..., 'E2n'],
...
I meant more that my answer was more "fun" than "useful." I can't
imagine a reason one wouldn't prefer a loop to an eval. :-)
On Mon, 2005-03-28 at 16:00, Zhuang Li wrote:
> Yes. I think it's both useful and fun. I was thinking something similar
> to
> @[EMAIL PROTECTED] = map{1} @a;
Well...
two solutions:
obvious one:
@a = ( 'E1', 'E2', 'E3', 'En' );
eval '$a{ ' . join( ' }{ ', @a ) . '} = 1';
print Dumper( \%a );
Interpreters rule :)
and 'hidden loop' one:
@a = ( 'E1', 'E2', 'E3', 'En' );
$a = 1;
map{ $a = { $_ => $a } } reverse @a;
print Dumper( $a );
bot
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',
> "ZL" == Zhuang Li <[EMAIL PROTECTED]> writes:
ZL> Hi, given an array: @a = ('E1', 'E2', ..., 'En');
ZL> Is there an easy way, hopefully one liner, to do the following without a
ZL> loop? If not, will Perl support this in Perl 6?
ZL> $hash->{E1}->{E2}->...->{En} = 1;
i think perl6
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;
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;
Thanks,
john
14 matches
Mail list logo