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

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.

主站蜘蛛池模板: 芒康县| 鄯善县| 新民市| 姚安县| 尼勒克县| 阿鲁科尔沁旗| 大余县| 彭山县| 汕尾市| 桂阳县| 遂川县| 临洮县| 仁化县| 舟山市| 定襄县| 车险| 盐源县| 炎陵县| 唐山市| 宝坻区| 乐山市| 浮梁县| 古浪县| 攀枝花市| 阿勒泰市| 石城县| 合川市| 宝鸡市| 大兴区| 和龙市| 嘉黎县| 新丰县| 隆回县| 陇川县| 庄浪县| 西藏| 拉萨市| 璧山县| 金湖县| 漳平市| 托克托县|