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

Declaring variables

Every variable must be declared before its use in the program. You don't need to declare all the variables at the beginning of the program. From a practical perspective, the point of declaration can (and should) be as close as possible to the place where it is first used. The most practical reason to do that is to make the visibility of the variable better—if you declare too early, you force the reader of your program to think about the purpose of the variable; on the other hand, if you make changes in the code, there is a big chance of forgetting to remove the variable declaration if it is not located close to the place it is used.

To declare a variable, use the my keyword, as shown here:

my $x;

It is possible to declare a variable together with initialization:

my $x = 42;

Perl 6 also defines the concept of constants. These are variables whose value can only  be set once in the initializer. To create a constant, use the constant keyword, as shown here:

constant $C = 10;

It is not possible to assign a new value to the constant.

Now, let's see what kind of variables are available in Perl 6.

主站蜘蛛池模板: 洪泽县| 崇礼县| 育儿| 托克逊县| 东方市| 定远县| 呼图壁县| 莱阳市| 永年县| 桐庐县| 巴楚县| 额尔古纳市| 区。| 民勤县| 富锦市| 吉安县| 纳雍县| 沙湾县| 丹江口市| 贺州市| 兖州市| 景洪市| 安丘市| 山东省| 瑞昌市| 五华县| 柳州市| 泽库县| 五指山市| 许昌市| 阿拉善左旗| 铜鼓县| 万全县| 崇明县| 阿尔山市| 合阳县| 龙岩市| 西安市| 淮北市| 资阳市| 楚雄市|