关闭

List and Array in Perl

标签: perl
478人阅读 评论(0) 收藏 举报
分类:

scalar ----singular

list && array ------plural



1. A list is an ordered collection of scalars, and the list is the data. Using (1, 2, 3)


2. An array is a variable that contians a list, and the array is the variable. Using ['1', '2'. '3']


Array and list can have any number of elements. The smallest one has no elements and the largest can fill all of the available memory. 

Perl's philosophy of " no unnecessary limits".

Using $#array_name as an index.

$array[-1] == $array[$#array]


3. fw shortcut


qw( fred barney betty wilma dino ) == ("fred", "barney", "betty", "wilma", "dino")


4, List assigment:

($fred, $barney)=("fred", "barney")


5, pop and push operations in List:

@array = 5..9;

$fred = pop(@array); #@array=(5.6,7,8)

$fred = pop(@@array); #@array=(5.6,7)


push(@array, 10);# @array =(5,6,7,10)


6. shift and unshift operations:

@array = qw# dino fred barney #;

$m = shift(#@array); # $m gets " dino"  and @array now has ("fred", "barney")

shift @array; #@array now is empty

unshift(@array, 5); # @array has one element (5)


7, Interpolating array into list:

@rock = qw{ a b c d }

$mail = "red@rock.cn" #wrong

$mail = "red\@rock.cn"; #right

$mail = 'red@rock.cn' #right

0
0
猜你在找
【套餐】Hadoop生态系统零基础入门
【套餐】嵌入式Linux C编程基础
【套餐】2017软考系统集成项目——任铄
【套餐】Android 5.x顶级视频课程——李宁
【套餐】深度学习入门视频课程——唐宇迪
【直播】广义线性模型及其应用——李科
【直播】从0到1 区块链的概念到实践
【直播】计算机视觉原理及实战——屈教授
【直播】机器学习之凸优化——马博士
【直播】机器学习&数据挖掘7周实训--韦玮
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:162790次
    • 积分:2936
    • 等级:
    • 排名:第11983名
    • 原创:105篇
    • 转载:217篇
    • 译文:0篇
    • 评论:1条
    文章分类