Do these three versions all behave differently?

use open qw( :encoding(UTF-8) :std );

use open qw( :encoding(UTF8) :std );

use open qw( :utf8 :std );

解决方案

Firstly, :utf8 only markes the text as UTF-8 it does not check that it is valid. See this post on PerlMonks for information.

:encoding is an Extension Layer to PerlIO, perl perldoc perliol

":encoding" use Encoding;

makes this layer available, although PerlIO.pm "knows" where to find it. It is an example of a layer which takes an argument as it is called thus: open( $fh, "<:encoding>

The other two questions are answered in the FAQ perldoc perlunifaq

What is the difference between ":encoding" and ":utf8"? Because UTF-8 is one of Perl's internal formats, you can often just skip the encoding or decoding step, and manipulate the UTF8 flag directly. Instead of ":encoding(UTF-8)", you can simply use ":utf8", which skips the encoding step if the data was already represented as UTF8 internally. This is widely accepted as good behavior when you're writing, but it can be dangerous when reading, because it causes internal inconsistency when you have invalid byte sequences. Using ":utf8" for input can sometimes result in security breaches, so please use ":encoding(UTF-8)" instead. Instead of "decode" and "encode", you could use "_utf8_on" and "_utf8_off", but this is considered bad style. Especially "_utf8_on" can be dangerous, for the same reason that ":utf8" can. There are some shortcuts for oneliners; see "-C" in perlrun.

What's the difference between "UTF-8" and "utf8"? "UTF-8" is the official standard. "utf8" is Perl's way of being liberal in what it accepts. If you have to communicate with things that aren't so liberal, you may want to consider using "UTF-8". If you have to communicate with things that are too liberal, you may have to use "utf8". The full explanation is in Encode. "UTF-8" is internally known as "utf-8-strict". The tutorial uses UTF-8 consistently, even where utf8 is actually used internally, because the distinction can be hard to make, and is mostly irrelevant. For example, utf8 can be used for code points that don't exist in Unicode, like 9999999, but if you encode that to UTF-8, you get a substitution character (by default; see "Handling Malformed Data" in Encode for more ways of dealing with this.) Okay, if you insist: the "internal format" is utf8, not UTF-8. (When it's not some other encoding.)

The open pragma (ie., use open) only sets the default PerlIO layers for input and output; :std does the following,

The ":std" subpragma on its own has no effect, but if combined with the ":utf8" or ":encoding" subpragmas, it converts the standard filehandles (STDIN, STDOUT, STDERR) to comply with encoding selected for input/output handles. For example, if both input and out are chosen to be ":encoding(utf8)", a ":std" will mean that STDIN, STDOUT, and STDERR are also in ":encoding(utf8)". On the other hand, if only output is chosen to be in ":encoding(koi8r)", a ":std" will cause only the STDOUT and STDERR to be in "koi8r". The ":locale" subpragma implicitly turns on ":std".

So :std is a subpragma (open.pm specific) that sets the Standard Streams to receive Unicode Input perl :utf8 as above.

java 转 utp-8,utf8和不同的utp8有何不同?相关推荐

  1. java写ansi_java实现utf8转换ansi

    打开"记事本"程序 Notepad.exe,新建一个文本文件,内容就是一个"严"字,依次采用 ANSI, Unicode,Unicode big endian ...

  2. Java txt文件 转 utf-8 格式

    Java txt文件 转 utf-8 格式 转载并修改来源:http://www.cnblogs.com/wangyanei2017/p/8807351.html import org.apache. ...

  3. java.sql.SQLException: Invalid utf8 character string: 'ACED00'

    使用JPA+Hibernate执行原生sql查询时报了异常,一开始以为是数据库编码的问题,尝试了几种方式都没有解决,静下来想了想,原来是查询的sql中有status in (?1),而传入的参数值是枚 ...

  4. java 转换gbk编码,java中GBK转UTF-8乱码的解决方法

    java中GBK转UTF-8乱码的解决方法 如果自己采用的是GBK编码,对方采用得到是UTF-8编码,发送数据时需要将GBK编码数据转换成UTF-8编码数据,这样对方才不会乱码. 问题出现:GBK转U ...

  5. JAVA输出带BOM的UTF-8编码的文件

    https://blog.csdn.net/comeonyangzi/article/details/81708134 当从http 的response输出CSV文件的时候,设置为utf8的时候默认是 ...

  6. java中byte, iso-8859-1, UTF-8,乱码的根源

    本文作者:@Ryan Miao 本文链接:https://www.cnblogs.com/woshimrf/p/java-utf8-iso-charset.html 版权声明: 本博客所有文章除特别声 ...

  7. java utf-8格式,JAVA编写文件格式转换UTF-8

    情景:接到个任务,需要将某路径下包括子目录下的所有文件都转换为UTF-8格式. 结果:生成FileTransfer.jar,通过批处理调用实现该功能. 没玩过java,先把环境整好吧. 需要以下工具: ...

  8. Java字符串编码转换UTF-8

    import java.io.UnsupportedEncodingException; /** * * * 描述:<p> 功能描述,该部分必须以中文句号结尾.</p> * 创 ...

  9. JAVA编写文件格式转换UTF-8

    情景:接到个任务,需要将某路径下包括子目录下的所有文件都转换为UTF-8格式. 结果:生成FileTransfer.jar,通过批处理调用实现该功能. 没玩过java,先把环境整好吧. 需要以下工具: ...

最新文章

  1. 如何赋能零售行业数字化转型? SAP从这些方向发力
  2. JDK14中的java tools简介
  3. 将整个表单设置为只读_如何将独立网站设置为制作中,阻止搜索引擎收录网站页面?...
  4. Scrapy网络爬虫框架实际案例讲解,Python爬虫原来如此简单!
  5. android关闭系统弹窗,Android 禁止 EditText 弹出软件盘
  6. NYOJ-背包问题(贪心)
  7. python带cookie提交表单自动登录(转)
  8. ActiveMQ学习:Hello ActiveMQ
  9. 百度云盘加速器for mac
  10. EPSON清零软件sscserve40使用方法
  11. [读史思考]北宋历史上几个外行项目经理
  12. 鸿蒙OS可以装电脑吗,组装台式机可以装鸿蒙系统吗?
  13. oa系统打不开只能重启服务器,oa系统打不开怎么办-oa系统打不开的解决方法 - 河东软件园...
  14. 【PyTorch深度学习项目实战100例】—— 基于ResNet50实现多目标美味蛋糕图像分类 | 第51例
  15. 论文笔记 NLPCC 2016|A Convolution BiLSTM Neural Network Model for Chinese Event Extraction
  16. 不建议轻易做量化玩高频
  17. iphone长截图哪个软件好_Windows长截图技巧、iPhone免费长截图软件
  18. [算法学习no7]图的遍历
  19. Cisco anyconnect 连接成功浏览器无法访问任何网页
  20. 【浙江大学C小程week6知识点整理】

热门文章

  1. 0003 64位Oracle11gR2不能运行SQL Developer的解决方法
  2. 解决 ModuleNotFoundError: No module named ‘requests‘ 问题
  3. 如何重设<input type = “file”>
  4. enctype =#39;multipart / form-data#39;是什么意思?
  5. 如何检查对象是否为数组?
  6. win11搜索栏无法输入 Windows11搜索栏无法输入的解决方法
  7. Win11应用商店怎么更新新版?应用商店更新教程
  8. EasyUI组件使用
  9. python求众数程序_求众数(python实现)
  10. 怎么锁定电脑屏幕_怎么录制视频?在电脑上录制视频的步骤详解