On 5/1/06, Ryan Perry <[EMAIL PROTECTED]> wrote:

Generally, your hash value is larger than you key ( $hash{key}="Some
text, maybe a sentence or two....").  Is there any reason I should
not reverse this relationship? ($hash{"Some text, maybe a sentence or
two...."}='key')

There's no law against it, if that's what you mean.

Why would you want to do it? One reason might be if you were keeping
track of some fixed-size piece of data (like a checksum) for each
potentially long data string (like a URL).

I don't see any special reason that long keys should be avoided,
except of course for whatever memory that they occupy. But anybody who
worries about memory usage is probably using the wrong language.
(Having said that, I should mention that perl does some clever
memory-saving tricks on hash keys that it can't do on values. And
maybe the other way around, too, for all I know.)

Of course, if you need to look up an element in the hash at run time,
you'll want to start with the key; you're correct that that's often
the smaller data item. For most uses of a hash, this asymmetry between
keys and values forces the programmer to choose as a key the data item
that's going to be available at runtime.

If you can choose freely which ones are keys and which are values, I'd
suggest that you code so that it makes the most sense to you, even if
that means long keys and short values.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to