I'm looking for a CPAN module that will take a short string:
my $hash_value = hash_this('short string not too long');
And hash it into an integer key:
say $hash_value;
12345671234 # an integer key
I'm looking for a CPAN module that will take a short string:
my $hash_value = hash_this('short string not too long');
And hash it into an integer key:
say $hash_value;
12345671234 # an integer key
Digest::MD5 should work:
http://search.cpan.org/~gaas/Digest-MD5-2.38/MD5.pm
With the binary, you should be able to convert it using it:
Math::BaseCnv
If you need an hash that is only 32-bit or 64-bit long*, that is, if you need an hash of the type used in computer science terms such as "hash table" and NOT an hash in the cryptography meaning (which CAN'T be that short and strong at the same time) you can use CRC32 or one of its friends.
OTOH if you need a cryptographically strong hash function, I would avoid MD5 and use SHA-256 nowadays.
use String::CRC32;
$crc = crc32("some string");
*: I don't know how big is a perl integer value, so I might be wrong there
I wrote Algorithm::Nhash to solve this exact problem. It generates a cheap hash from a string and optionally does modulo arithmetic to throw the strings into buckets.