in reply to Re: initialize all values in a hash
in thread initialize all values in a hash
"You could do it with a tied hash, but I can't find a module that does this on CPAN, so you'd need to do it yourself."
OK, I've just gone and uploaded Hash::DefaultValue to CPAN. Usage:
tie my %hash, 'Hash::DefaultValue', 60; $hash{foo} = 8; say $hash{foo}; # says 8 say $hash{bar}; # says 60
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: initialize all values in a hash
by DrHyde (Prior) on May 18, 2012 at 14:03 UTC | |
by tobyink (Canon) on May 18, 2012 at 14:27 UTC | |
by DrHyde (Prior) on May 18, 2012 at 15:35 UTC | |
by tobyink (Canon) on May 18, 2012 at 16:49 UTC |