如何在 Perl 中比较两个字符串? [英] How do I compare two strings in Perl?

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

问题描述

如何在 Perl 中比较两个字符串?

How do I compare two strings in Perl?

我正在学习 Perl,我在 StackOverflow 上查过这个基本问题,但没有找到好的答案,所以我想我会问.

I am learning Perl, I had this basic question looked it up here on StackOverflow and found no good answer so I thought I would ask.

推荐答案

参见 perldoc perlop.对字符串使用 ltgteqnecmp比较:

See perldoc perlop. Use lt, gt, eq, ne, and cmp as appropriate for string comparisons:

二进制 eq 如果左参数在字符串上等于右参数,则返回 true.

Binary eq returns true if the left argument is stringwise equal to the right argument.

二进制 ne 如果左参数在字符串上不等于右参数,则返回 true.

Binary ne returns true if the left argument is stringwise not equal to the right argument.

二进制 cmp 返回 -1、0 或 1,具体取决于左参数在字符串上是小于、等于还是大于右参数.

Binary cmp returns -1, 0, or 1 depending on whether the left argument is stringwise less than, equal to, or greater than the right argument.

Binary ~~ 在其参数之间进行智能匹配....

Binary ~~ does a smartmatch between its arguments. ...

ltlegegtcmp 使用排序规则(排序)如果遗留使用区域设置(但不是 use locale ':not_characters')有效,则由当前区域设置指定的顺序.请参阅perllocale.不要将这些与 Unicode 混合,只与旧的二进制编码混合.标准 Unicode::Collat​​eUnicode::Collat​​e::Locale 模块为整理问题提供了更强大的解决方案.

lt, le, ge, gt and cmp use the collation (sort) order specified by the current locale if a legacy use locale (but not use locale ':not_characters') is in effect. See perllocale. Do not mix these with Unicode, only with legacy binary encodings. The standard Unicode::Collate and Unicode::Collate::Locale modules offer much more powerful solutions to collation issues.

这篇关于如何在 Perl 中比较两个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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