5 ms·
Another solution could be to lock the keys of $config after its been configured: use Hash::Util 'lock_keys'; our $config; $config->{file_paht} = "/opt/a
by draegtun 15y ago
Another solution could be to lock the keys of $config after its been configured:
use Hash::Util 'lock_keys';
our $config;
$config->{file_paht} = "/opt/app/data_file";
lock_keys( %$config );
Now any attempt to use an undefined key will throw an error. So on the open() it would now throw error: Attempt to access disallowed key 'file_path' in a restricted hash at...
- douglashunter 15y agoThis is what Kris Arnold (https://twitter.com/wka https://twitter.com/wka), one of the other hackers here at Shutterstock recommended. I like it.
- draegtun 15y agoMe to, especially as it covers both problems you've given in the post. Now I just need to get into the habit of using Hash::Util::lock_keys more often myself :)