Posts Tagged ‘yaml’

Instant mysql connection with perl.

Monday, September 29th, 2008

Reading about the exciting concept of code speed vs programmer time. That is, balancing what it costs to make a machine run slow code, vs what it costs to let a coder work easier.

Convenience.

So.. I noticed I was coding stuff that uses a mysql connection, and I store the connection variables, the credentials- in a YAML configuration file. Often. It’s good practice. YAML files are simple, and you can store them anywhere- this helps keep sensittive data, or .. the data that makes the same app act different- appart from the executable application.

I was helping a co-worker learn some perl, and he wanted to connect to a db. He was sort of impatient- because the details of establishing a connection with a new language are a little bit… beneath him? This is someone highly trained and skilled in other languages and systems. And he wanted to just.. *have* a connection handle to a database.

So… YAML.. DBH…. I wrote and released YAML::DBH.

As simple as it gets. You write a config file:


password: super
user: myself
database: superstuff

In your script:

use YAML::DBH ‘yaml_dbh’;

my $dbh = yaml_dbh(’./credentials.yml’);