在多行上定义 - 或“//”

问题描述 投票:7回答:1

为什么版本1,2和3工作,但版本4失败时:Null regex not allowed在多行上使用//

#1
say Nil         //
    try {'a'++} //
    1;

#2
say    Nil
    // try {'a'++} //
       2;

#3
say   Nil
   // 3;

#Fails with: Null regex not allowed
say        Nil
        // try {'a'++}
        // 4;
perl6
1个回答
15
投票

在一条线的末端有try块。它是一样的

say        Nil
    // try {'a'++};
    // 4;

参见文档:It is OK to skip the semicolon between the last statement in a block and the closing }.

你可以试试

say        Nil
    // try {'a'++}\
    // 4;

要么

say        Nil
    // (try {'a'++})
    // 4;
© www.soinside.com 2019 - 2024. All rights reserved.