This seems to be a simple syntax error. The DSN string is too long:
qq(dbi:SQLite:dbname=$db,'','',{ ...
The qq() extends beyond the first comma, which is not what you want. You want:
qq(dbi:SQLite:dbname=$db),'','',{ ...
Usually, in such situations, I try to separate the steps:
my $dsn = "qq(dbi:SQLite:dbname=$db)";
my $user;
my $password;
my %dbi_options = (
RaiseError => 1,
PrintError => 1,
sqlite_open_flags => SQLITE_OPEN_READONLY,
);
my $dbh = DBI->connect($dsn, $user, $password, \%dbi_options);