An Introduction to Class::DBI - Introduction 4

The Problem

Ugly

  • embedding one language (SQL) into another (Perl) is ugly:

        sub lookup_film_nominations {
             my ($first, $last) = @_;
             my $sth = <<EOQ;
                 SELECT n.year, n.type,
                   FROM nomination n,
                        film f
                  WHERE film.id = nomination.film_id
                    AND film.title like ?
                    AND film.year >= ?
    
        EOQ
    
        $sth->prepare() or die "could not prepare: $DBI::errstr\n";
        $sth->execute("%Lord of the Rings%", 2000, 2005) or die "could not prepare: $DBI::errstr\n";
    

 

YAPC::Canada << Previous | Index | Next >>
Copyright © 2003 Michael Graham