Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: My UTF-8 text isn't surviving I/O as expected

by ibm1620 (Hermit)
on Nov 23, 2024 at 22:35 UTC ( [id://11162854]=note: print w/replies, xml ) Need Help??


in reply to Re: My UTF-8 text isn't surviving I/O as expected
in thread My UTF-8 text isn't surviving I/O as expected

THANK YOU!! That cleared up a lot. I didn't even suspect that the culprit was sqlite.

I still have trouble reading UTF-8 from command line arguments. I assume this is not a Perl issue; any suggestions how to fix?

#!/usr/bin/env perl
use v5.40;
use utf8;
use open qw(:std :encoding(UTF-8));

my $utf8_text1 = shift;
say "A variable set from argument on command line";
show ($utf8_text1);

my $utf8_text2 = 'Åke Lindström;
say "A variable set to UTF8 literal";
show($utf8_text2);

chomp (my $utf8_text3 = <>);
say "A variable set by reading from STDIN";
show($utf8_text3);

sub show($str) {
    say "Binary:      ", join ' ', (unpack "H*", $str) =~ m/../g ;
    say "Text>STDOUT: $str";
}
Output:
$ echo "Åke Lindström" | u 'Åke Lindström'
A variable set from argument on command line
Binary:      c3 85 6b 65 20 4c 69 6e 64 73 74 72 c3 b6 6d
Text>STDOUT: Åke Lindström
A variable set to UTF8 literal
Binary:      c5 6b 65 20 4c 69 6e 64 73 74 72 f6 6d
Text>STDOUT: Åke Lindström
A variable set by reading from STDIN
Binary:      c5 6b 65 20 4c 69 6e 64 73 74 72 f6 6d
Text>STDOUT: Åke Lindström
  • Comment on Re^2: My UTF-8 text isn't surviving I/O as expected

Replies are listed 'Best First'.
Re^3: My UTF-8 text isn't surviving I/O as expected
by choroba (Cardinal) on Nov 23, 2024 at 22:50 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11162854]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2025-07-12 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.