如何在Perl中转储一个字符串,看看是否有任何字符差异? [英] How can I dump a string in perl to see if there are any character differences?

查看:115
本文介绍了如何在Perl中转储一个字符串,看看是否有任何字符差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶尔会遇到与字符串不同的问题,在某些情况下, utf8 :: all 改变了行为,所以我假设微妙的差异是unicode。我想以这样一种方式转储字符串,使我的差异是可视化的。我这样做的选择是什么?

I've occasionally had problems with strings being subtly different, in some cases utf8::all changed the behavior, so I assume the subtle differences are unicode. I'd like to dump strings in such a way that the differences will be visual to me. What are my options for doing this?

推荐答案

我推荐转储 Perl核心中的 Devel :: Peek 模块中的功能

I recommend the Dump function in the Devel::Peek module in the Perl core:

$ perl -MDevel::Peek -e 'Dump "abc"'
SV = PV(0x10441500) at 0x10491680
  REFCNT = 1
  FLAGS = (PADTMP,POK,READONLY,pPOK)
  PV = 0x10442224 "abc"\0
  CUR = 3
  LEN = 4

$ perl -MDevel::Peek -e 'Dump "\x{FEFF}abc"'
SV = PV(0x10441050) at 0x10443be0
  REFCNT = 1
  FLAGS = (PADTMP,POK,READONLY,pPOK,UTF8)
  PV = 0x10449bc0 "\357\273\277abc"\0 [UTF8 "\x{feff}abc"]
  CUR = 6
  LEN = 8

(你看到如何 FLAGS 在第二个例子中包含 UTF8 ,因为宽字符,但不是在第一个?)

(You see how FLAGS contains UTF8 in the second example, because of the wide character, but not in the first?)

这篇关于如何在Perl中转储一个字符串,看看是否有任何字符差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆