Created
July 24, 2008 11:01
-
-
Save sids/2118 to your computer and use it in GitHub Desktop.
Perl: Unicode handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://gist.github.com/2118 | |
Unicode handling in Perl. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; use warnings; | |
binmode STDIN, ':utf8'; | |
binmode STDOUT, ':utf8'; | |
while (<STDIN>) { | |
print STDOUT $_; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; use warnings; | |
use Encode qw(encode_utf8 decode_utf8); | |
while (my $in = <STDIN>) { | |
my $s = decode_utf8($in); | |
my $out = encode_utf8($s); | |
print STDOUT $out; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $dbh = DBI->connect($dsn, $db_username, $db_password, {RaiseError => 1}) | |
or die "Couldn't connect to database: $DBI::errstr\n"; | |
my $set_utf8_sql = qq{SET NAMES 'utf8';}; | |
$dbh->do($set_utf8_sql); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment