官术网_书友最值得收藏!

The -c command

The -c command-line checks the syntax of the program and exits. It also runs the BEGIN and CHECK blocks in the program, which are discussed in the section Phasers of Chapter 2, Writing Code later in this book. This command-line option is useful if you only want to check that there are no syntax errors in the code and don't want to execute it, with the exception being the code in the BEGIN and CHECK code blocks.

In the case of correct programming, it prints the following output:

Syntax OK

If there were compile-time errors, the compilation will stop at the first error and will display it on the console, mentioning the line number where it found an error.

The error message contains the description of the error and indicates the exact place in the code with the help of the eject character (). If your console supports colors, the fragment of the code before the eject character is green, and the rest of the line is red.

Here is an example of a program that misses the closing quote for the string:

say "Hello;

Run it to check the syntax, as shown here:

$ perl6 -c err.pl

The program did not compile, and this is what the compiler prints:

===SORRY!=== Error while compiling /Users/ash/code/err.pl
Unable to parse expression in double quotes; couldn't find final '"' 
at /Users/ash/code/err.pl:2
------> <BOL><EOL>
    expecting any of:
        argument list
        double quotes
        term
主站蜘蛛池模板: 浮山县| 民丰县| 苏尼特右旗| 祥云县| 固阳县| 右玉县| 蒲城县| 洛川县| 乐业县| 胶州市| 扎兰屯市| 浮山县| 遂宁市| 从化市| 合阳县| 凤庆县| 茂名市| 九寨沟县| 迁西县| 柞水县| 开平市| 南平市| 安塞县| 广昌县| 特克斯县| 寿宁县| 搜索| 湄潭县| 中江县| 浦城县| 三都| 泰顺县| 巨野县| 三穗县| 仙居县| 潮州市| 高青县| 临邑县| 屏东市| 阜城县| 上饶县|