See How hash really works for a discussion of this topic. In short, as long as you specify a key (not interpolating q {}), you can use any characters you want.
Regarding Danaโs answer, no, it wonโt take longer until the longer keys are agreed: it will take infinitely longer to hash the key, but thatโs it.
For reference, this is a hash function in Perl 5.10.0:
#define PERL_HASH(hash,str,len) STMT_START { register const char * const s_PeRlHaSh_tmp = str; register const unsigned char *s_PeRlHaSh = (const unsigned char *)s_PeRlHaSh_tmp; register I32 i_PeRlHaSh = len; register U32 hash_PeRlHaSh = PERL_HASH_SEED; while (i_PeRlHaSh--) { hash_PeRlHaSh += *s_PeRlHaSh++; hash_PeRlHaSh += (hash_PeRlHaSh << 10); hash_PeRlHaSh ^= (hash_PeRlHaSh >> 6); } hash_PeRlHaSh += (hash_PeRlHaSh << 3); hash_PeRlHaSh ^= (hash_PeRlHaSh >> 11); (hash) = (hash_PeRlHaSh + (hash_PeRlHaSh << 15)); } STMT_END
Pedro silva
source share