in reply to Re^2: re-initialize the hash
in thread re-initialize the hash
use strict; use warnings; use Data::Dumper; my @array=('a',0,'b',0,'c',0); my %hash=('a'=>1 , 'b' =>2 , 'c'=>3,); %hash=@array; print Dumper \%hash;
Your version has the advantage that if some of the keys should change, you still would reset them to 0. If you want to reset all values to 0 you don't need the array anymore:
@hash{keys %hash}=(0) x scalar(keys %hash);
CORRECTION:Forgot () around the 0. And as cdarke pointed out to me the scalar is not needed as it is already in scalar context. But I tend to play safe with these things instead of trusting my memory
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: re-initialize the hash
by cdarke (Prior) on Apr 01, 2010 at 09:19 UTC | |
|
Re^4: re-initialize the hash
by vennila (Novice) on Apr 01, 2010 at 10:09 UTC |