如何在 Perl 中显示扩展 ASCII 代码字符?
如何显示 192 个字符的符号( └ )珀尔?
How to display 192 character symbol ( └ ) in perl ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何显示 192 个字符的符号( └ )珀尔?
How to display 192 character symbol ( └ ) in perl ?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
你想要的是能够打印unicode,答案就在
perldoc perluiintro
。您可以使用
\x{nnnn}
其中 n 是十六进制标识符,或者您可以使用以下名称执行\N{...}
:What you want is to be able to print unicode, and the answer is in
perldoc perluniintro
.You can use
\x{nnnn}
where n is the hex identifier, or you can do\N{...}
with the name:要准确使用这些代码,您的终端必须支持代码页 437,其中包含框架。或者,您可以使用派生的 CP850 来减少拳击字符。
此类装箱字符也以 Unicode 块元素 的形式存在。 Perl 中所需的字符被标记为
\N{U+2514}
。更多详细信息请参见 perlunicodeTo use exactly these codes your terminal must support Code Page 437, which contains frames. Alternatively you can use derived CP850 with less boxing characters.
Such boxing characters also exist as Unicode Block Elements. The char which you want in perl is noted as
\N{U+2514}
. More details in perlunicode这看起来像代码页 437 编码。 Perl 可能只是输出您给它的字节。您的终端可能需要 UTF8。
因此,您需要将其解码为 Unicode,然后将其重新编码为 UTF-8。
编辑:正确的编码。
That looks like the Code page 437 encoding. Perl is probably just outputting bytes that you give it. And your terminal is probably expecting UTF8.
So you need to decode it to Unicode, then re-encode it in UTF-8.
EDIT: Correct encoding.
像往常一样,Jon Skeet 指出了这一点:
192
代码位于“扩展 ASCII 中”范围。我建议您遵循@Douglas Leeder的建议,但我不确定 www.LookupTables.com 为您提供了哪种编码;ISO-8859-1
认为 192 映射为“À”,而Mac OS Roman
认为它是“¿”。As usual, Jon Skeet nails it: the
192
code is in the "extended ASCII" range. I suggest you follow @Douglas Leeder's advice, but I'm not sure which encoding www.LookupTables.com is giving you;ISO-8859-1
thinks 192 maps to "À", andMac OS Roman
thinks its "¿".有没有适用于所有角色的解决方案?
用户说他们想使用 latin-1 扩展字符集字符 - 所以让我们尝试一下此块中的示例!因此,如果他们想要
Æ
字符,他们会运行...输出:
�
完全可测试的在线演示
Perl 中的 TDLR 字符编码模式
那么,等等,刚刚发生了什么?您会注意到调用 UTF-8 的其他方式,例如
char(...)
、\N{U+...}
,甚至unpack(...)
也有同样的问题。没错——问题不在于这些函数,而在于底层的字符抽象层。在这种情况下,您需要在代码中尽早指示该层。输出:
Æ
现在我可以正确拼写'Ælf'!
完整可测试的在线演示
为什么会发生这种情况?
PerlDoc 中有一个关于
chr()
函数的注释< /strong>....因此,这个特殊的块需要有特殊的
use open
来指示std编码。Is there a solution that works on ALL characters?
The user says they wanted to use an latin-1 extended charset character — so let's try an example from this block! So, if they wanted the
Æ
character, they would run...Output:
�
Full Testable, Online Demo
TDLR Character Encoding Modes in Perl
So, wait, what just happened there? You'll notice that other ways of invoking UTF-8, such as
char(...)
,\N{U+...}
, and evenunpack(...)
also have the same issue. That's right -- the problem isn't with any of these functions, but an underlying character abstraction layer. In this case, you'll want to indicate this layer early in your code..Output:
Æ
Now I can spell 'Ælf' correctly!
Full Testable, Online Demo
Why did that happen?
There is a note within the PerlDoc regarding the
chr()
function....For this reason, this special block needs to have that special
use open
to indicate std encoding.