Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: prevent stringification for hash-keys

by 1nickt (Canon)
on Feb 16, 2019 at 23:47 UTC ( #1230008=note: print w/replies, xml ) Need Help??

in reply to prevent stringification for hash-keys

See the core module Hash::Util.

use strict; use warnings; use Hash::Util 'lock_keys'; my $key = 'foo'; lock_keys my %hash, ($key, 'bar'); $hash{$key}++; $hash{'key'}++; __END__
$ perl Attempt to access disallowed key 'key' in a restricted hash at 1230007 line 11.

Hope this helps!

The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: prevent stringification for hash-keys
by morgon (Priest) on Feb 16, 2019 at 23:52 UTC
    That's sort of a solution, but I still would need to explicitely call lock_keys on every hash I use.

    What I really want is a way to make $hash{bare_word} a compile-time error in a lexical scope...

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1230008]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2023-05-30 23:20 GMT
Find Nodes?
    Voting Booth?

    No recent polls found