perl - Why am I getting 0E0 for the return value of the DBI "execute" method? -
i have written sample perl program delete data database table.
this code have written,
use dbi; $dbh = dbi->connect("dbi:pg:host=192.168.12.23;port=5432;", "adhi"); if ( $dbh ) { print "connected successfully\n"; $exe = $dbh->prepare("delete perl_test.test"); $res = $exe->execute(); if ( $res ) { print "deleted table of rows: $res\n"; } }
if have executed above should print successful message , number of rows deleted.
if table empty printing 0e0
instead of 0
. don't know how returning value this?
can please explain me how working?
it done in way allow test whether operation successful. reason '0e0'
(as string) true value, 0
false value in perl. therefore:
you can test return value in
if
determine whether operation successful (true means success),but can use return value number know exact number of deleted rows, since 0e0 evaluates 0 when used number.
if need number of deleted rows, can use $res + 0
or $res * 1
. after have tested operation successful.
Comments
Post a Comment