Perl 三点运算符...示例 [英] Perl three dot operator ... examples

查看:56
本文介绍了Perl 三点运算符...示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能用一些例子来说明 ..... 运算符之间的确切区别?

Can anybody show with some examples the exact difference between .. and ... operator?

来自 perlop 手册页:

如果您不希望它在下一个之前测试正确的操作数评估,就像在 sed 中一样,只需使用三个点(...")而不是两个.

If you don't want it to test the right operand until the next evaluation, as in sed, just use three dots ("...") instead of two.

但这究竟是什么意思?我不明白 perlop 的例子:

But what exactly this mean? I don't understand the perlop's example:

@lines = ("   - Foo",
          "01 - Bar",
          "1  - Baz",
          "   - Quux"
);
foreach (@lines) {
    if (/0/ .. /1/) {
        print "$_\n";
    }
}

with ... 将打印 Baz - 但为什么呢?更准确地说,为什么 Baz 没有用两个点打印而只用 ... 打印?

with ... will print the Baz - but why? More precisely, why is Baz not printed with two dots and only with ...?

推荐答案

«...»在真正的翻牌过牌之后不会立即进行翻牌过牌.

«...» doesn't do a flop check immediately after a true flip check.

用«..»,

With «..»,

  1. " - Foo"
  1. /0/ 返回 false.
  2. .. 返回 false.
  1. /0/ returns false.
  2. .. returns false.

  • 01 - 条形"

    1. /0/ 返回真.翻转!
    2. /1/ 返回真.翻牌!
    3. .. 返回真(因为第一次检查为真).
    1. /0/ returns true. Flip!
    2. /1/ returns true. Flop!
    3. .. returns true (since the first check was true).

  • "1 - 巴兹"

    1. /0/ 返回 false.
    2. .. 返回 false.
    1. /0/ returns false.
    2. .. returns false.

  • " - Quux"

    1. /0/ 返回 false.
    2. .. 返回 false.
    1. /0/ returns false.
    2. .. returns false.

  • 随着 «...»,

    With «...»,

    1. " - Foo"
    1. /0/ 返回 false.
    2. ... 返回 false.
    1. /0/ returns false.
    2. ... returns false.

  • 01 - 条形"

    1. /0/ 返回真.翻转!
    2. ... 返回 true.
    1. /0/ returns true. Flip!
    2. ... returns true.

  • "1 - 巴兹"

    1. /1/ 返回真.翻牌!
    2. ... 返回 true.
    1. /1/ returns true. Flop!
    2. ... returns true.

  • " - Quux"

    1. /0/ 返回 false.
    2. ... 返回 false.
    1. /0/ returns false.
    2. ... returns false.

  • 这篇关于Perl 三点运算符...示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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