当我插入 Berkeley DB 时,为什么会收到来自 Perl 的宽字符警告?
我正在 Berkeley DB 上进行实验。我只是从 DB a 中删除内容并将键值对重新插入到 DB b 中。但是,将键值对插入此数据库 b 时出现宽字符错误。帮助?
I'm running an experiment on Berkeley DBs. I'm simply removing the contents from DB a and reinserting the key-value pairs into DB b. However, I am getting Wide character errors when inserting key-value pairs into this DB b. Help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
BerkeleyDB 存储字节(“八位字节”)。 Perl 字符串由 Perl 字符组成。为了将 Perl 字符存储在基于八位字节的存储中,您必须将字符转换为字节。这称为编码,就像字符编码一样。
您收到的警告表明 Perl 正在为您进行转换,并猜测您要使用的字符编码。因为它可能会猜错,所以最好明确地说出来。编码模块允许您做到这一点。
不要写:
你应该写:
并且在出路时:
这不仅适用于 BDB;还适用于 BDB。每当您通过网络、文件、终端或几乎任何其他方式进行通信时,您必须确保在传出时将字符编码为八位字节,并在传入时将八位位组解码为字符。否则,您的程序将不会工作。
BerkeleyDB stores bytes ("octets"). Perl strings are made of Perl characters. In order to store Perl characters in the octet-based store, you have to convert the characters to bytes. This is called encoding, as in character-encoding.
The warning you get indicates that Perl is doing the conversion for you, and is guessing about what character encoding you want to use. Since it will probably guess wrong, it's best to explicitly say. The Encode module allows you to do that.
Instead of writing:
You should instead write:
And on the way out:
This is true of more than just BDB; whenever you are communicating across the network, via files, via the terminal, or pretty much anything, you must be sure to encode characters to octets on the way out, and decode octets to characters on the way in. Otherwise, your program will not work.