perl6变量类型学习
来源:互联网 发布:守望先锋最新伤害数据 编辑:程序博客网 时间:2024/06/03 20:59
详见注释…
#Perl 6 variables are classified into 3 categories: Scalars, Arrays and Hashes.#A sigil (Sign in Latin) is a character that is used as a prefix to categorize variables.#--------------Scalars begins here----------#$ is used for scalars#Stringmy $name='John Doe';#a line of perl6 code must be ended with ';'say $name.uc;#to uppercasesay $name.chars;# number of charssay $name.flip;#reverse#Integermy $age=99;say $age.is-prime;#Both String and Integer start with $,#which means holds one value or referencemy $num = 2.3;say $num.numerator;#分子say $num.denominator;#最小分母say $num.nude;#--------------Scalars ends here----------#-------------- Arrays begins here----------#@ is used for arrays#Arrays are lists containing multiple values.my @animals = '123', 'cd', 'hg';#The array accept any number of values#thus,length is auto-extendingsay "the number of animals is"~@animals.elems~"animals";#The tilde ~ is used for string concatenationsay "The animals is: " ~ @animals;say "I want to add an element";@animals.push("hehe");#add element to an Arrayssay "Animal is:"~@animals;say "What I put in last is:"~@animals[3];@animals.pop;#delete last oe elementsay "We're going to remove: " ~ @animals.splice(1,2) ~ " and keep the " ~ @animals;#splice(a,b) will remove b elements starting at position a.my @test[3];#This array will be able to hold a maximum of 3 values, indexed from 0 to 2.@test[0]="hehe";@test[1]="xixi";@test[2]="haha";say @test;#Multidimensional arraysmy @tbl[3;2];#Think of it as a 3x2 grid or array.@tbl[0;0]=1;@tbl[0;1]="he";@tbl[1;0]=2;@tbl[1;1]="ha";@tbl[2;0]=3;@tbl[2;1]="hei";say @tbl;=podVisual representation of the array:[1 x][2 y][3 z]=cut#-------------- Arrays ends here----------#-------------- Hashes begins here----------=podA Hash is a set of Key/Value pairs.% is used for Hashes=cutmy %capital=('uk','London','China','beijing');my %capital_copy=("uk"=>"London","China"=>"beijing");say %capital==%capital_copy;#Truesay %capital;say %capital_copy;%capital.push: ("France" =>'Paris');#equals %capital.push: (France =>'Paris');#.push: (key ⇒ 'Value') adds a new key/value pair.say %capital.kv;say %capital.keys;say %capital.values;#-------------- Hashes ends here----------
0 0
- perl6变量类型学习
- perl6学习
- perl6
- linux学习 变量类型
- C++学习-变量类型
- 学习笔记(变量&基本类型)
- 学习变量和基本类型
- C++ Primer 学习 《变量类型》
- Python学习之变量类型
- JavaScript学习之变量类型
- Java学习·变量类型
- 学习笔记---变量的类型
- Lua学习-类型与变量
- 【Shell脚本学习6】Shell变量:Shell变量的定义、删除变量、只读变量、变量类型
- AS3 学习笔记 一 变量、类型
- Javascript学习笔记-----类型、值和变量
- C++学习--变量和基本类型
- 黑马视频学习笔记-变量类型
- js属性操作
- eclipse中出现The con“structor 'NimbusLookAndFeel()' is not API ”的解决办法
- MFC单文档之串口通讯实现16进制数据的发送和接收
- linux下软件安装、卸载、运行
- 修改VMware虚拟机网卡MAC地址的方法总结
- perl6变量类型学习
- 分治法求逆序对
- 16:踩方格
- 关于viewHolder的优化
- day36_spring配置文件
- java面试题集锦
- 单片机==日常复习
- 3.1面向对象的概念
- 坚持#162天~做事有做事的方法