Hello everybody,
I created a small SQLite database that I want to use in my Perl script
Code:
#!/usr/bin/perl -w
use strict;
use warnings;
use DBI;
use DBD::SQLite;
use POSIX 'strftime';
my $now = strftime "%d%m%Y_%H%M%S", localtime;
my $db_handle=DBI->connect("dbi:SQLite:dbname=myDB.db") == 0 or die "$DBI::errstr\n";
$db_handle->do( "DROP TABLE routers" ) or die "$DBI::errstr\n";
$db_handle->do( "DROP TABLE modules" ) or die "$DBI::errstr\n";
$db_handle->do( "CREATE TABLE routers(NAME VARCHAR(20) PRIMARY KEY, IOS VARCHAR(200), RAM INTEGER, FLASH INTEGER, WLC VARCHAR(20), AIM VARCHAR(20))" ) or die "$DBI::errstr\n";
$db_handle->do( "CREATE TABLE modules(NAME VARCHAR(200), DESCR VARCHAR(200), PID VARCHAR(200), VID VARCHAR(3), SN VARCHAR(11) PRIMARY KEY, ROUTER VARCHAR(20), FOREIGN KEY(ROUTER) REFERENCES routers(NAME))" ) or die "$DBI::errstr\n";
system("sqlite3", "myDB.db", ".import A512_routers.table routers") == 0 or die "Import of routers table failed";
system("sqlite3", "myDB.db", ".import A512_modules.table modules") == 0 or die "Import of modules table failed";
$db_handle->do( "CREATE TABLE routers_$now AS SELECT * FROM routers" ) or die "$DBI::errstr\n";
$db_handle->do( "CREATE TABLE modules_$now AS SELECT * FROM modules" ) or die "$DBI::errstr\n";
$db_handle->disconnect;
if I run it like this, the script fails at this line
Code:
my $db_handle=DBI->connect("dbi:SQLite:dbname=myDB.db") == 0 or die "$DBI::errstr\n";
telling me
Use of uninitialized value in concatenation (.) or string at ./test.pl line 12.
line 12 is the line I am showing you
on the other hand if I remove the die part so it looks like this
Code:
my $db_handle=DBI->connect("dbi:SQLite:dbname=myDB.db");
the program runs fine and the data is indeed imported and new tables are created
I am interested in your opinions why this is happening and what is causing it
thank you very much for your replies in advance