Can I safely require Perl's DBI instead of using it? -


i have large script has no database connection yet. need 1 tiny new feature. safe add naked block require dbi need or need import something?

# lots of no-database code here... $obj; {   require dbi;   $dbh = dbi->connect('dsn');   $obj = modulethatneedsdbh->new(dbh => $dbh); } $obj->fancystuff(); # more no-database code... 

the block keep $dbh hidden rest of program of course.

by default dbi module imports nothing calling package yes, in theory use require instead of use.

but hoping gain this? in case use dbi equivalent begin { require dbi }, , if omit begin block imposing lengthy process of loading package during run time undesirable.

note must handle failure connect database.

my $dbh = dbi->connect('dsn', 'user', 'pass')             or die $dbi::errstr; 

although dying may little extreme in case.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -