tphyahoo has asked for the wisdom of the Perl Monks concerning the following question:
I don't undersatnd this idiom
which is used here for code that runs (I checked), but I don't understand the @{ $n{ $mag } } part.my @keys = qw( 0 0.1 0.3 1 3 10 30 1000 ); my %n; for ( my $mag = 5.0 ; $mag < 9.0 ; $mag += 0.1 ) { @{ $n{ $mag } }{ @keys } = ( 0 ) x @keys; }
It seems kind of like a hash slice, for example
as described at this explanation of the x operator.my @keys = qw(a b c d); my %hash; @hash{@keys} = (1) x @keys;
But there seems to be more dereferencing, or something, going on... I don't get it. Is this a hash slice or some other thing?
UPDATE: On reflection, I believe my confusion was all about the brackets for setting hash values. Where do you have to leave them out, where can you leave them in... and where does it work both ways? See my post further down.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is this a hash slice?
by Roy Johnson (Monsignor) on Mar 31, 2005 at 15:49 UTC | |
|
Re: Is this a hash slice?
by tlm (Prior) on Mar 31, 2005 at 15:55 UTC | |
|
Re: Is this a hash slice?
by webfiend (Vicar) on Mar 31, 2005 at 18:55 UTC | |
|
Re: Is this a hash slice?
by tphyahoo (Vicar) on Mar 31, 2005 at 17:59 UTC | |
|
Re: Is this a hash slice?
by tphyahoo (Vicar) on Mar 31, 2005 at 19:10 UTC | |
by Roy Johnson (Monsignor) on Apr 01, 2005 at 02:43 UTC |