Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How to make a fingerprint from an Object

by Moron (Curate)
on May 07, 2007 at 17:44 UTC ( [id://613993]=note: print w/replies, xml ) Need Help??


in reply to How to make a fingerprint from an Object

You could use Digest::MD5 but that only operates on one string. In general, an object is a blessed reference to a compound data structure which doesn't automatically fit. So the real challenge is to figure out a unique way to convert the data structure to a single string that can be converted to MD5. Data::Dumper won't can guarantee a unique key ordering (see reply below from tinita). , so you'd need to sort the structure by hash key before delimiting, although arrays should be used in existing order ( $; = ASCI(19), non-printing, is also a useful delimiter for printable data ).

The only thing that occurs to me though is that fingerprinting the whole object shouldn't be necessary - it should be sufficient to fingerprint an ordered, delimited concatenation of selected instance fields. It is more usual (though not necessarily mandatory) for this to be the primary key in the logical data model rather than some bulk data field.

Update: You could also consider storing the MD5 in the database, setting a UNIQUE constraint on some selection of fields and letting the database deal with the problem.

__________________________________________________________________________________

^M Free your mind!

  • Comment on Re: How to make a fingerprint from an Object

Replies are listed 'Best First'.
Re^2: How to make a fingerprint from an Object
by tinita (Parson) on May 07, 2007 at 20:42 UTC
    Data::Dumper won't guarantee a unique key ordering
    oh, it does =)
    just set $Data::Dumper::Sortkeys to 1

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-25 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found