Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在寻找一个需要短字符串的 CPAN 模块:
my $hash_value = hash_this('short string not too long');
并将其散列成一个整数键:
say $hash_value; 12345671234 # an integer key
摘要::MD5 应该可以工作:
http://metacpan.org/pod/Digest::MD5
使用二进制文件,您应该能够使用它进行转换:
数学::BaseCnv
如果您需要一个只有 32 位或 64 位长的散列*,也就是说,如果您需要计算机科学术语中使用的类型的散列,例如“散列表”,而不是密码学意义上的散列(即不能同时又短又强)您可以使用 CRC32 或其朋友之一。
OTOH,如果您需要加密强大的哈希函数,我现在会避免使用 MD5并使用 SHA-256。
use String::CRC32; $crc = crc32("some string");
*: 我不知道 perl 整数值有多大,所以我可能错了
我写了Algorithm::Nhash来解决这个确切的问题。它从一个字符串生成一个廉价的散列,并可选地进行模运算以将字符串放入存储桶中。