What is the Perl equivalent of Ruby "foo" .hash?

The hash method on a Ruby String returns a number based on the length and content of the string:

>> "foo".hash
=> 876516207

What is equivalent in Perl?

+3
source share
3 answers

If you want to get an arbitrary line digest, check out the Digest module in CPAN, which supports MD5 and SHA1 / 2. You can crop the result for any number of characters that you need.

+5
source

Ruby, , String, - Perl. rb_str_hash().

+3

Just out of curiosity, what are you going to use the hash for? The Digest module is probably good enough for most purposes, but there are some cases where you might want to roll your own. Rare, but possible.

+2
source

Source: https://habr.com/ru/post/1727890/


All Articles