http://www.perlmonks.org?node_id=137795


in reply to Hash Tie's DESTROY & DBI

Some error handling might be nice:
$DBI->do("blah"); if ($DBI->err) { print "Error: ", $DBI->errstr, "\n"; }
Also you might want to consider placeholders, it makes quoting and stuff a lot less error prone:
foreach (@STRUCTURE) { push @list, "$_ = ?"; push @vals, $impl->{$_}->{value}; } my $string = join ",",@list; $DBH->do(qq{ UPDATE $TABLENAME SET $string WHERE $KEY=? LIMIT 1 }, undef, @vals, $keyval);
Hope this is of some help.

Replies are listed 'Best First'.
Re: Re: Hash Tie's DESTROY & DBI
by tretin (Friar) on Jan 11, 2002 at 05:16 UTC

    so by saying that die does not work in your script, that means that you tried and die did not work or did not produce any error (or something of that nature) or you assumed it would not, or something else? I am interested to know (since I do not know much about DBI) why it would not work there.

    I know many do not like to useeval because of security reasons but, if you used it (in correspondence w/ $@) would that catch the errors if die did/could not? or would it not work for the same reason die would not/could not?

    thank you for your time

    -tretin
      I know many do not like to use eval because of security reasons

      eval "$data_from_tainted_source" has both security and performance issues.
      eval { block_of_code() } does not (at least not due to the eval itself), and die'ing in an eval then checking $@ is a common method of 'exception handling' in perl.