Hello members, I wrote the code like below:
try { $dbh = DBI->connect("dbi:mysql:database=$db;host=$host;port=$port", $user, $passwd) or croak $DBI::errstr; } catch { if ($_) { write_log($_); exit 1; } }; The problem is, when the connection fails, it write the error message to logs, but also print them to the terminal. So I add a statement and the code like below: try { local $SIG{'__WARN__'} = sub {}; $dbh = DBI->connect("dbi:mysql:database=$db;host=$host;port=$port", $user, $passwd) or croak $DBI::errstr; } catch { if ($_) { write_log($_); exit 1; } }; Now everything seems work fine. The error message has been written to logs only, no output to the terminal. My question is , is it the correct way for doing this? Thanks in advance.