Re: Option to warn/die on fetch with invalid hash key?
[email protected] ("Ricardo Signes")
| Newsgroups | perl.perl5.porters |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Dec 26, 2025, at 21:06, Sam Kington wrote:
> Schwern’s answer mentions Hash::Util, which appears to do what you want?
> […]
> I’m sure there are performance implications of doing this, though.
Why? I don't see a clear reason this would be slow, and measuring doesn't show any significant difference.
Both of these consistently come in at 0.12 ± 0.005 seconds for me.
perl -MHash::Util=lock_keys -e '%hash = map {; $_ => $_ } (0 .. 1_000); for (1 .. 1_000_000) { my $x = $hash{ int(rand() * 1_000) } }'
perl -MHash::Util=lock_keys -e '%hash = map {; $_ => $_ } (0 .. 1_000); lock_keys(%hash); for (1 .. 1_000_000) { my $x = $hash{ int(rand() * 1_000) } }'
--
rjbs