code:
# A:
$dbh->do(qq/insert into foo(cl) values('test')/);
# B:
$dbh->do(qq/insert into foo(cl) values('test')/) or warn $dbh->errstr;
# C:
eval { $dbh->do(qq/insert into foo(cl) values('test')/); };
warn "error : $@ " if $@;
All would output :
DBD::mysql::db do failed: Duplicate entry 'test' for key 'cl' at a.pl line 9.
I dont want this arbitrary warning/error message send to stderr. I’d like use warn $dbh->errstr.
perl a.pl 2>/dev/null would suppress the error message, but I want to know how to do this in script?
You need to install your own error handler. E.g.
Error handlers are described in DBI POD
Another options are to:
Set
PrintWarnattribute to false value (courtesy of Sinan’s answer on some forumTrap all warnings via a signal handler:
$SIG{'__WARN__'} = sub {};