如何在Perl中使用Chr()和Ord()函数

The Perl programming language's chr() and ord() functions are used to convert characters into their ASCII or Unicode values and vice versa. Chr() takes an ASCII or Unicode value and returns the equivalent character, and ord() performs the reverse operation by converting a character to its numeric value. 

Perl编程语言的chr()ord()函数用于将字符转换为ASCII或Unicode值,反之亦然。 Chr()采用ASCII或Unicode值并返回等效字符,而ord()通过将字符转换为其数值来执行相反的操作。

Perl Chr()函数 ( Perl Chr() Function )

The chr() function returns the character represented by the number specified. For example:

chr()函数返回由指定数字表示的字符。 例如:

#!/usr/bin/perl

#!/ usr / bin / perl

print chr (33)

打印字符(33)

print "/n";

打印“ / n”;

print chr (36)

打印CHR(36)

print "/n";

打印“ / n”;

print chr (46)

打印CHR(46)

print "/n";

打印“ / n”;

When this code is executed, it produces this result:

执行此代码后,将产生以下结果:

!

$

$

&

Note: The characters from 128 to 255 are by default not encoded as UTF-8 for backward compatibility reasons.

注意:出于向后兼容的原因,默认情况下从128到255的字符未编码为UTF-8。

Perl的Ord()函数 ( Perl's Ord() Function )

The ord() function does the opposite. It takes a character and converts it into its ASCII or Unicode numeric value.

ord()函数的作用与此相反。 它接受一个字符并将其转换为ASCII或Unicode数字值。

#!/usr/bin/perl

#!/ usr / bin / perl

print ord ('A');

打印订单('A');

print "/n";

打印“ / n”;

print ord ('a');

打印ord('a');

print "/n";

打印“ / n”;

print ord ('B');

打印ord('B');

print "/n";

打印“ / n”;

When executed, this returns:

执行后,将返回:

65

65

97

97

66

66

You can confirm the results are accurate by checking an ASCII Code Lookup Table online.

您可以通过在线检查ASCII码查找表来确认结果是否正确。

关于Perl ( About Perl )

Perl was created in the mid-'80s, so it was a mature programming language long before websites exploded in popularity. Perl was originally designed for text processing, and it is compatible with HTML and other markup languages, so it quickly became popular with website developers. Perl's strength lies in its ability to interact with its environment and its cross-platform compatibility. It can easily open and manipulate many files within the same program. 

Perl创建于80年代中期,因此它是一种成熟的编程语言,早于网站开始流行。 Perl最初是为文本处理而设计的,它与HTML和其他标记语言兼容,因此很快在网站开发人员中流行。 Perl的优势在于与环境交互的能力以及跨平台的兼容性。 它可以轻松地打开和处理同一程序中的许多文件。

翻译自: https://www.thoughtco.com/perl-chr-ord-functions-quick-tutorial-2641190

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值