in reply to basic dbi question

If you find yourself repeating yourself repeating yourself too much too much, you can also cobble-together a little sub vaguely like this one:

sub prepare_execute { # (sql, what) my ($sql, $what) = @_; my $sth=$dbh->prepare($sql) # '$dbh' IS GLOBAL... or die "can't prepare $what: $dbh->errstr"; $sth->execute or die "can't execute $what: $sth->errstr"; return $sth; }
... or whatever else you want to put in there.   This is “strictly shorthand,” but sometimes shorthand is what you really want.   If you find yourself doing the same thing over and over and over again, put it into a local sub.

Replies are listed 'Best First'.
Re^2: basic dbi question
by Anonymous Monk on Dec 01, 2010 at 22:41 UTC
    i wanted the prepare statement outside the loop because i believe it is quicker that way? I have millions of records