Class::Phrasebook Class::Phrasebook 3 of 23 : [PREV] [NEXT]

Design Patterns

Have you ever written a Perl application that connects to a database? If so, then you probably faced a problem of having some code like:

$statement = q(select isbn from book where title = 'Design Patterns');

$sth = $dbh->prepare($statement) ;

Why is this "a problem"? It looks like nice code, doesn't it? Actually, if you look at the code above, you will see two languages: Perl and SQL.

  • This can make the code difficult to read.
  • The same (or similar) SQL statements can appear in several places.
  • Difficult for an SQL Expert (non-Perl) to optimise the code.

© 2003 Barbie Home