in reply to Using Perl and MySQL for Activity Log

Well, the general logic/flow could look like this:

# $person is an object holding a record with getters for each field. if( record_exists( $person->id() ) ) { log_change( update_record( $person ) ); } else { log_new( add_record( $person ) ); }

The rest is sort of fill-in-the-blanks, but you seem to already know how to handle DB work, so I don't think that's where you're having trouble. If that's the issue, you'll have to be more specific as to what kind of help you were after.

You should be using placeholders though, with your DB access. See the documentation for DBI for more info. Placeholders improve security as well as providing for easier code maintenance.

By the way: Are you sure that keying off of a person's phone number is a good idea? You're sure to get multiple entries for the same individual. People never can recall what number they used when they first interacted with an organization. Was it my cell? My home? My office? My Google Voice? My Skype? My wife's cell? Was it my old AT&T cell, or my new Verizon one? Addresses aren't exactly ideal either; people move more than you might guess. Email addresses change too. It's really hard to ensure that you don't end up with duplicates regardless of how you maintain the database, but phone numbers are a weak starting point. If human interaction is a possibility, the person at the front line could always ask, "Are you Mr Spacey from Los Angeles, or Mr Spacey from Detroit?"


Dave