In my script, I previous connected and disconnected to the database within every subroutine. Now I have made changes and it now connect/disconnect to mysql only once within main:: (at the start and end of script respectively). Although my script works fine, I am wondering whether this is the best way.
I'm not very familiar with the debugger, but I tried it and it reported MySQL has gone away and then it stopped. I expected the debugger to go through all the subroutines within the script, but it doesn't. Does the output of the debugger point to a problem? As said the script behaves as expected when I run it. $ perl -dT usermap.cgi Loading DB routines from perl5db.pl version 1.32 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(usermap.cgi:23): my $session = initialise_session(); DB<1> c Set-Cookie: token_id=75cf9b9da31cf21ce755a3a6971049e2; path=/ Date: Sun, 28 Jul 2013 02:54:37 GMT Content-Type: text/html; charset=ISO-8859-1 Don't know what to do here. Did you pass any parameter? at usermap.cgi line 107 DBD::mysql::db do failed: MySQL server has gone away at /usr/local/share/perl5/CGI/Session/Driver/mysql.pm line 50. at /usr/local/share/perl5/CGI/Session/Driver/mysql.pm line 50 CGI::Session::Driver::mysql::store('CGI::Session::Driver::mysql=HASH(0x3499de0)', '75cf9b9da31cf21ce755a3a6971049e2', '$D = {\'_SESSION_ETIME\' => 7200,\'_SESSION_ID\' => \'75cf9b9...') called at /usr/local/share/perl5/CGI/Session.pm line 251 CGI::Session::flush('CGI::Session=HASH(0x2036e90)') called at /usr/local/share/perl5/CGI/Session.pm line 92 CGI::Session::DESTROY('CGI::Session=HASH(0x2036e90)') called at usermap.cgi line 129 eval {...} called at usermap.cgi line 129 (in cleanup) DBD::mysql::db do failed: MySQL server has gone away at /usr/local/share/perl5/CGI/Session/Driver/mysql.pm line 50. Debugged program terminated. Use q to quit or R to restart, use o inhibit_exit to avoid stopping after program termination, h q, h R or h o to get additional info. DB<1> w Adding a watch-expression requires an expression DB<1> excerpt from my code. 48 my $dbh = db_connect(); 107 die "Don't know what to do here. Did you pass any parameter?\n"; 108 } 22 $dbh->do(qq{UPDATE user SET login_status = 'N' WHERE login_status = 'Y' AND last_active < DATE_SUB(CURRENT_TIMESTAMP,INTERVAL $log_in_time2live MINUTE)}) || 123 warn "Couldn't update database table user:$DBI::errstr\n"; 124 125 126 $dbh->disconnect; 127 128 129 exit 0; Thanks Mimi