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:

  1. you can test return value in if determine whether operation successful (true means success),

  2. 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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -