use DBI; use threads; use threads::shared; my $driver = 'SQLite'; my $database = ''; my $dsn = ''; my $userid = ''; my $password = ''; my $dbh; my $dsn; my $stmt; my $sth; my $rv; my @row; my %hash; my %hsh :shared; my $int :shared; my $String; my $Sdatabase; $Sdatabase = $ARGV[0]; print 'Database fully qualified path of existing SQLite DB -> ' . $Sdatabase . "\n"; $dsn = "DBI:$driver:dbname=$Sdatabase"; print 'Database data source name for connect -> ' . $dsn . "\n"; $dbh = DBI->connect($dsn, $userid, $password, { PrintError => 1, RaiseError => 1, AutoCommit => 0, ReadOnly => 1 }); print 'Simple database handle in $dbh from connect -> ' . $dbh . " and DB is now open\n"; $hash{"$Sdatabase"} = $dbh; print 'Simple database handle in non-shared Hash, $Sdatabase -> ' . $Sdatabase . ' and $hash{"$Sdatabase"} -> ' . $hash{"$Sdatabase"} . "\n"; $stmt = qq(select count ( * ) from asnipv4 ); $sth = $hash{"$Sdatabase"}->prepare( $stmt ); $rv = $sth->execute(); while( @row = $sth->fetchrow_array()) { $Iknt++; $String = join ',', @row; print "$Iknt -> $String \n"; } $hash{$Sdatabase}->disconnect(); delete $hash{$Sdatabase}; # $int = $dbh; #print 'Try to get simple database handle in shared scalar $int as -> ' . $int . "\n"; $int = shared_clone(\$dbh); print 'Try to get simple database handle in shared scalar $int via shared_clone(\$dbh) -> ' . $int . " <- the original handle is gone and now we have a reference\n"; $hash{"$Sdatabase"} = $int; print 'Try to get shared scalar $int database handle into a non-shared Hash $Sdatabase -> ' . $Sdatabase . ' and $hash{"$Sdatabase"} -> ' . $hash{"$Sdatabase"} . " <- works but we have a reference and not the handle\n"; $hsh{"$Sdatabase"} = $int; print 'Try to get shared scalar $int database handle into a shared Hash $Sdatabase -> ' . $Sdatabase . ' has $hsh{"$Sdatabase"} -> ' . $hsh{"$Sdatabase"} . " <- BUT the simple = results in some other reference\n"; $stmt = qq(select count ( * ) from asnipv4 ); $sth = $hsh{"$Sdatabase"}->prepare( $stmt ); $rv = $sth->execute(); while( @row = $sth->fetchrow_array()) { $Iknt++; $String = join ',', @row; print "$Iknt -> $String \n"; } $hsh{$Sdatabase}->disconnect(); delete $hsh{$Sdatabase}; exit; #### [root@itx2 ~]# perl x7.pl /opt/asd/sql/dbi-indexed-GeoLite2.db-sqlite-old Database fully qualified path of existing SQLite DB -> /opt/asd/sql/dbi-indexed-GeoLite2.db-sqlite-old Database data source name for connect -> DBI:SQLite:dbname=/opt/asd/sql/dbi-indexed-GeoLite2.db-sqlite-old Simple database handle in $dbh from connect -> DBI::db=HASH(0x561e4b5e5480) and DB is now open Simple database handle in non-shared Hash, $Sdatabase -> /opt/asd/sql/dbi-indexed-GeoLite2.db-sqlite-old and $hash{"$Sdatabase"} -> DBI::db=HASH(0x561e4b5e5480) 1 -> 511665 Try to get simple database handle in shared scalar $int via shared_clone(\$dbh) -> REF(0x561e4b2b9570) <- the original handle is gone and now we have a reference Try to get shared scalar $int database handle into a non-shared Hash $Sdatabase -> /opt/asd/sql/dbi-indexed-GeoLite2.db-sqlite-old and $hash{"$Sdatabase"} -> REF(0x561e4b2b9570) <- works but we have a reference and not the handle Try to get shared scalar $int database handle into a shared Hash $Sdatabase -> /opt/asd/sql/dbi-indexed-GeoLite2.db-sqlite-old has $hsh{"$Sdatabase"} -> REF(0x561e4b5e5630) <- BUT the simple = results in some other reference Can't call method "prepare" on unblessed reference at x7.pl line 66. [root@itx2 ~]#