Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How to hash a string--not data structure

by haukex (Archbishop)
on Apr 17, 2023 at 19:36 UTC ( [id://11151721]=note: print w/replies, xml ) Need Help??


in reply to How to hash a string--not data structure

Careful - there is no such thing as "a reduced-length unique string that uniquely represents the original". Unless you're talking about lossless compression, when you reduce the length of the string (i.e. "hash it"), you lose information, and there is always a small but real chance of collisions. So replace the two instances of "unique" in your sentence with "almost unique", and then your question has an answer.

It sounds to me like you are looking for Digest and one of the many algorithms such as MD5, SHA-1, SHA-256, SHA-512, etc. - Digest::MD5 and Digest::SHA are in the core. If you want a shorter checksum with a larger chance of collisions, there are also algorithms like CRC32 with corresponding modules on the CPAN.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11151721]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2024-03-28 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found