perl 字符和字节 表示utf8

时间:2022-02-19 08:39:49
[oracle@oadb sbin]$ cat insertdb.pl 
use DBI;
use Encode;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
use Net::SMTP;
my $a="老干妈";
# $a=encode_utf8($a);
print length($a);
print "\n";
print $a;



my $dbName = 'oadb';
my $dbUser = 'query';
my $dbUserPass = 'kjk7787czcb';
my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass) or die "can't connect to database ";
$dbh->do("insert into tlcb values('$a')");

[oracle@oadb sbin]$ perl insertdb.pl
9
老干妈[oracle@oadb sbin]$

这里是字节长度

[oracle@oadb sbin]$ cat insertdb.pl
use DBI;
use Encode;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
use Net::SMTP;
my $a="老干妈";
$a=decode_utf8($a);
print length($a);
print "\n";
print $a;



my $dbName = 'oadb';
my $dbUser = 'query';
my $dbUserPass = 'kjk7787czcb';
my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass) or die "can't connect to database ";
$dbh->do("insert into tlcb values('$a')");

[oracle@oadb sbin]$ perl insertdb.pl
3
Wide character in print at insertdb.pl line 9.
老干妈[oracle@oadb sbin]$

这里表示3个字符