in reply to Capturing SQL errors in Perl

Aside from the best practices that have already been suggested, and that you should follow, there is one thing that at first glance indicate a point of failure. You are trying to build your query based on the values that those $a_* variables have. But you are passing them inside single quotes, and what goes inside single quotes is not interpolated. So, what you are really trying to insert is what you actually can read on that line of code, not the values of the variables.

Also, instead of the custom error message, use the one DBI gives you with DBI->errtsr

update: Thanks Crackers2 and Narveson, you are absolutely right. Please ignore this post.

Replies are listed 'Best First'.
Re^2: Capturing SQL errors in Perl
by Crackers2 (Parson) on Apr 17, 2008 at 18:11 UTC
    You are trying to build your query based on the values that those $a_* variables have. But you are passing them inside single quotes, and what goes inside single quotes is not interpolated.

    No, only the outermost quotes determine whether interpolation will happen or not. Since those are double quotes it will work fine. Minimal example:

    my $var = test'; my $result = "This is a '$var' again"; print "$result\n";

    $var will be interpolated and This is a 'test' again will be printed.

Re^2: Capturing SQL errors in Perl
by Narveson (Chaplain) on Apr 17, 2008 at 18:13 UTC
    But you are passing them inside single quotes, and what goes inside single quotes is not interpolated.

    Wrong. The single quotes are inside a double-quoted string.

    The original version is not best practice, but it won't fail until one of the interpolated variables contains an embedded quote.

    my $name = 'Larry'; my $sql = "Insert into Users (name) values ('$name')"; print $sql; # Insert into Users (name) values ('Larry')