use utf8; # expect UTF-8 text in this source code
use open qw(:std :encoding(UTF-8)); # do UTF-8 encoding on I/O and STD*
####
00000000 c3 83 c2 85 6b 65 20 4c 69 6e 64 73 74 72 c3 83 |....ke Lindstr..|
00000010 c2 b6 6d |..m|
####
#!/usr/bin/env perl
use v5.40;
# brian d foy recommends using these settings
# (https://stackoverflow.com/a/47946606/522385):
# (1) recognize UTF-8 in this source code:
use utf8;
# (2) do the right things for writing and reading UTF-8, including to STD*:
use open qw(:std :encoding(UTF-8));
my $utf8_text1 = "Ã
ke Lindström"; # contains UTF8 chars:
say "A variable set to a UTF8 literal within perl program";
show ($utf8_text1);
use DBI;
my $dbh = DBI->connect( "dbi:SQLite:dbname=:memory:", "", "",
{ RaiseError => 1, AutoCommit => 1 } );
$dbh->do('CREATE TABLE names (name_id CHAR PRIMARY KEY, name CHAR)');
$dbh->do(qq{INSERT INTO names VALUES("nm0512537", "$utf8_text1")});
my $aoa_ref = $dbh->selectall_arrayref(
q{SELECT name FROM names WHERE name_id="nm0512537"}
);
say "\nUTF-8 text stored in, and retrieved from, sqlite DB:";
show($aoa_ref->[0][0]);
sub show($str) {
say "Binary: ", join ' ', (unpack "H*", $str) =~ m/../g ;
say "Text>STDOUT: $str";
}