Skip to content

Instantly share code, notes, and snippets.

@sids
Created July 24, 2008 11:01
Show Gist options
  • Save sids/2118 to your computer and use it in GitHub Desktop.
Save sids/2118 to your computer and use it in GitHub Desktop.
Perl: Unicode handling
http://gist.github.com/2118
Unicode handling in Perl.
#!/usr/bin/perl
use strict; use warnings;
binmode STDIN, ':utf8';
binmode STDOUT, ':utf8';
while (<STDIN>) {
print STDOUT $_;
}
#!/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;
}
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