in reply to Is this a hash slice?
What I didn't realize going into this, is that this is a situation where it works both ways. The following demo clears things up to my satisfaction.
Thanks, brother monks!
use strict; use warnings; use Data::Dumper; #Populate the hash the first way. my @keys = qw(a b c d e f); my %hash; @hash{@keys} = (1,1,1,1,1,1); # first verse. print Dumper(\%hash); #clear %hash. for (keys %hash) { delete $hash{$_}; } print Dumper(\%hash); #Populate the hash the second way, using scalars and arrays. ${hash}{a} = 1; $hash{b} = 1; # proving brackets optional when setting hash values in +$calar mode. @{hash}{('c','d')} = (1,1); @hash{'e','f'} = (1,1); # proving brackets optional when setting hash +values in @rray mode # second verse, same as the first. print Dumper(\%hash);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is this a hash slice?
by Roy Johnson (Monsignor) on Apr 01, 2005 at 02:43 UTC |