- Perl 6 Deep Dive
- Andrew Shitov
- 215字
- 2021-07-03 00:05:47
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.
- Python深度學習
- Production Ready OpenStack:Recipes for Successful Environments
- Learning SQLite for iOS
- 你必須知道的204個Visual C++開發問題
- Apache Kafka Quick Start Guide
- C語言程序設計
- Selenium Testing Tools Cookbook(Second Edition)
- MySQL入門很輕松(微課超值版)
- 軟件項目管理實用教程
- 人工智能算法(卷1):基礎算法
- Java 從入門到項目實踐(超值版)
- Instant Zurb Foundation 4
- ASP.NET 4.0 Web程序設計
- 算法設計與分析:基于C++編程語言的描述
- 從零開始學Selenium自動化測試:基于Python:視頻教學版