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

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
主站蜘蛛池模板: 苍南县| 竹溪县| 玉屏| 滕州市| 辉县市| 合肥市| 乌拉特后旗| 莆田市| 邢台县| 墨玉县| 台前县| 泉州市| 千阳县| 浮梁县| 乌拉特后旗| 彝良县| 洛川县| 洪泽县| 奉节县| 麦盖提县| 常德市| 波密县| 乐都县| 延寿县| 荔浦县| 康定县| 井研县| 资中县| 蕉岭县| 紫金县| 宣汉县| 长葛市| 五大连池市| 宜宾县| 庆元县| 临朐县| 邻水| 韶山市| 公安县| 怀宁县| 四平市|