Yitzchak Scott-Thoennes wrote:
To set it, you need to just do the same thing except that at each step
instead of keeping the hash element, you keep a reference to it:
$entryref = \$hash;
$entryref = \$$entryref-{$_} for @a;
$$entryref = 1;
Note that this will create hashrefs at any undefined
On Tue, Mar 29, 2005 at 11:45:01AM +0200, Alexandre Jousset wrote:
Yitzchak Scott-Thoennes wrote:
To set it, you need to just do the same thing except that at each step
instead of keeping the hash element, you keep a reference to it:
$entryref = \$hash;
$entryref = \$$entryref-{$_} for @a;
Yitzchak Scott-Thoennes wrote:
I'm sorry but that doesn't work as is on my system: Not a HASH
reference at x.pl line 9..
Works for me. Can you show the actual code you are trying?
In fact I made a mistake. Sorry again, you're right ! :-)
--
\^/
-/ O
wrote:
[snip code...]
gives:
$VAR1 = {
'E1' = {
'E2' = {
'E3' = {
'En' = 1
}
},
'E3' = {
Alexandre Jousset wrote:
Andrew Pimlott wrote:
(You should be able to write the first one as
${fold_left { \${$_[0]}-{$_[1]} } \$hash, @a} = 1;
Is it a copy/paste or a retype ? Because there's a comma missing after
the first closing brace...
but Perl complains for no reason I can see.)
--
On Tue, Mar 29, 2005 at 06:42:41PM +0200, Alexandre Jousset wrote:
Alexandre Jousset wrote:
Andrew Pimlott wrote:
(You should be able to write the first one as
${fold_left { \${$_[0]}-{$_[1]} } \$hash, @a} = 1;
Is it a copy/paste or a retype ? Because there's a comma missing
Zhuang Li writes:
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;.
Yeah, like this:
%hash{dims @a} = (1) xx Inf;
What I'd really like to
-Original Message-
From: Luke Palmer [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 29, 2005 5:43 AM
To: Zhuang Li
Cc: Jeff Yoak; fwp@perl.org; perl6-language@perl.org
Subject: Re: Unknown level of hash
Zhuang Li writes:
Yes. I think it's both useful and fun. I was thinking
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
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
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
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 );
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... that's
-Shabanski [mailto:[EMAIL PROTECTED]
Sent: Monday, March 28, 2005 4:02 PM
To: fwp@perl.org
Subject: Re: Unknown level of hash
two solutions:
obvious one:
@a = ( 'E1', 'E2', 'E3', 'En' );
eval '$a{ ' . join( ' }{ ', @a ) . '} = 1';
print Dumper( \%a );
Interpreters rule
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',
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 without a
ZL loop? If
I always found the code to do this WITH a loop quite funny in fact:
my $work = \$hash;
$work = \$$work-{$_} for @a;
$$work = 1;
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 series of
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;
If you're feeling
20 matches
Mail list logo