I am writing a script which is likely to be modified by users. Currently I am storing the configuration settings inside the script. It exists in the form of a hash-of-hashes.
I would like to guard against people accidentally using lowercase characters in the hash keys, because that will break my script.
It would be simple to inspect the hash keys and merely issue warnings for any keys with lowercase characters, but I would rather fix the case sensitivity automatically.
In other words, I want to convert all the hash keys in the top-level hash to uppercase.
Andy’s answer is a good answer, except he
ucs every key, and thenucs it again if it doesn’t match.This
ucs it once:But since you spoke of users storing keys, a tie is a much more sure way, even if slower.
And then in main:
That’s a show. The
tie‘magic’ encapsulates it, so the users can’t unknowingly mess with it.Of course, as long as you’re using a ‘class’, you can pass in the config file name and initialize it from there:
Where you would have to call it like:
…assuming some constant
CONFIG_FILE_PATH.