* Ovid <[EMAIL PROTECTED]> [2005-08-14 05:40]:
> Because I frequently find that missing keys are OK; I just need
> to assign default values to them if they're not present.  Thus,
> if I call lock_keys before hand, it doesn't work.

That makes no sense; you seem unaware that you can define *any*
set of permissible keys:

    lock_keys( %args, "foo", "bar" );

None of these keys need already be set. `%args` does not have to
have a “foo” or a “bar” key at the time you are locking it.

Hence the

    lock_keys( %args, keys %args, @optional_keys );

idiom in the sample code I wrote in my previous mail, which
constrains the hash to the set of the keys already in it (with
default values) *plus* a couple of others.

> If I call lock_keys afterward, I then I still have to remember
> to unlock them when my methods are done with the hash.

A minor inconenvience?

> I don't want to lock the keys. I want to validate them.

Just unlock the keys after using the lock as validation…

I really think that, barring objections such as “I MUST support
Perls < 5.8” or such, the lock/unlock thing is the simplest way
of doing this.

Even if I’ve not convinced you, I know this will be what I’ll be
doing henceforth. :-)

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

Reply via email to