Windows 10, Strawberryperl 5.16.3, pp
If I pack the following two scripts with pp, the first work, the second not (Can't connect to data source 'DBI:SQLite:\C:\Users\DON\Desktop\data.db' because I can't work out what driver to use (it doesn't seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is not set) at script/myscript.pl). In the first, the database path is hard encoded, in the second it is read by a configuration file (in the example a simple text file). Note that both works nicely from command line
use warnings; use strict; use DBI; use DBD::SQLite; my $Path='C:\Users\DON\Desktop\data.db'; my $dsn = "DBI:SQLite:" . $Path; print "Connecting $dsn ... \n"; my %attr = (RaiseError => 1, sqlite_unicode => 1, AutoCommit = +> 1); my $dbh = DBI->connect($dsn, "", "", \%attr) || die $DBI::errs +tr; print "done!\n";
And here the second script, reading the same $Path value from file
use warnings; use strict; use DBI; use DBD::SQLite; my $Path; print "Reading configuration file...\n"; my $FileInput="config.txt";#simple txt file containing this: C +:\Users\DON\Desktop\data.db open my $FH, "<:encoding(UTF-8)", $FileInput; while (my $line = <$FH>) { $Path = $line; } my $dsn = "DBI:SQLite:" . $Path; print "Connecting $dsn ... \n"; my %attr = (RaiseError => 1, sqlite_unicode => 1, AutoCommit = +> 1); my $dbh = DBI->connect($dsn, "", "", \%attr) || die $DBI::errs +tr; print "done!\n";
What is wrong in the second script that pp doesn't like?
In reply to pp concatenate path by IB2017
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |