in reply to Class::DBI and database name

Yes - I had excactly the same issue. Here is how I resolved it:

In the DB module:

#!/usr/bin/perl -w use strict; use warnings; use Class::DBI; package AvalancheDB; our $DBPath="avalanchedata.sqlite"; # Default file nme our $DBH; sub import{ my ($class,$newpath)=@_; $DBPath = $newpath || $DBPath; #print "IMPORT: Setting path to '$DBPath' \n\t \n"; ## Delay this setting till AFTER IMPORT !! AvalancheDB::DBI->connection(qq|dbi:SQLite:dbname=$DBPath|, "", "") or die "Cannot connect to Database at $DBPath;"; } ...
In the MAIN code...
... my $ProgramDir; BEGIN{ ($ProgramDir) = ( $0=~m|(.+)\/.+$|, $0=~m|(.+)\\.+$| ,"."); } use lib ( $ProgramDir, ); # Current Program's Dir use AvalancheDB ("$ProgramDir/avalanchedata.sqlite"); ...
Basically, I'm (ab)using the "import" function to get the DB path.

     Syntactic sugar causes cancer of the semicolon.        --Alan Perlis

Replies are listed 'Best First'.
Re^2: Class::DBI and database name
by alexbio (Monk) on Jun 28, 2010 at 13:23 UTC

    Thank you very much for the help, but that's not precisely what I wanted.

    Anyway, I resolved by using your code and setting the db path with File::Temp so that user is no longer asked to set it manually.

    Alex's Log - http://alexlog.co.cc