- Perl 6 Deep Dive
- Andrew Shitov
- 230字
- 2021-07-03 00:05:48
Arrays
Array variables can host more than one value. The values can be of the same type, or can be of different types. Arrays are often used to keep lists of data items.
Arrays in Perl 6 are prefixed with the @ sigil. To access the elements of an array, the postfix pair of square brackets is used. For example, the second element of the @a array is @a[1]. Note that indexing starts from zero.
Let's take a look at how to create an array of integer numbers:
my @odd_numbers = 1, 3, 5, 7, 9, 11;
Alternatively, you can use parentheses or angle brackets. The following two arrays are the same as the previous one:
my @array2 = (1, 3, 5, 7, 9, 11);
my @array3 = <1 3 5 7 9 11>;
When printing it using the say built-in function, Perl 6 prints the content of the array in square brackets, as you can see here:
say @odd_numbers; [1 3 5 7 9 11]
Here is another example of an array that contains data of mixed types:
my @array = 1, 'two', 3E-2;
All the elements here are of different types (integer, string, and floating-point value), but they can easily be accessed via their index:
say @array[0]; # 1
say @array[1]; # two
say @array[2]; # 0.03
Let's take a further look at the possibilities that arrays offer in Perl 6.
- Mastering OpenLayers 3
- ASP.NET Web API:Build RESTful web applications and services on the .NET framework
- PyTorch自動駕駛視覺感知算法實(shí)戰(zhàn)
- NLTK基礎(chǔ)教程:用NLTK和Python庫構(gòu)建機(jī)器學(xué)習(xí)應(yīng)用
- 神經(jīng)網(wǎng)絡(luò)編程實(shí)戰(zhàn):Java語言實(shí)現(xiàn)(原書第2版)
- Learning Elixir
- Oracle BAM 11gR1 Handbook
- 表哥的Access入門:以Excel視角快速學(xué)習(xí)數(shù)據(jù)庫開發(fā)(第2版)
- Mastering Apache Maven 3
- JavaCAPS基礎(chǔ)、應(yīng)用與案例
- Mastering ArcGIS Enterprise Administration
- 深入淺出Go語言編程
- MATLAB GUI純代碼編寫從入門到實(shí)戰(zhàn)
- Serverless Web Applications with React and Firebase
- R語言實(shí)戰(zhàn)(第2版)