List and Array in Perl

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值