in reply to Re: hash key confusion
in thread hash key confusion

Which is better?

# This? if( exists $hash{ sprintf "%#x", ord('a') } ) { ... } # or this? if( exists $hash{a} ) { ... }

I'd say that we don't know enough about his needs to make the determination that he ought to be storing stringified hexadecimal values as hash keys. There may be specific cases where that's useful, but in the general case it smells bad to me.

It almost seems like he's trying to create a hash that crossreferences hex values with literal characters. That's working too hard, when chr, ord, and sprintf already have the conversions down pat.


Dave

Replies are listed 'Best First'.
Re^3: hash key confusion
by locked_user sundialsvc4 (Abbot) on Mar 25, 2014 at 00:14 UTC

    In making my recommendation, I don’t / didn’t know that there was any sort of “intrinsic meaning” in the keys that the OP intends to store.   If the true target of his intentions is, indeed, characters, versus the hex/binary representations of the same, then obviously a blind binary-to-hex conversion would not be sufficient for his/her purposes.   (In which case, “good catch.”)