List and Array in Perl

原创 2013年12月02日 16:17:35

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 = "" #wrong

$mail = "red\"; #right

$mail = '' #right

Perl Learning 2 List&Array

【本文原创,转载请说明】 List是标量的有序集合(数据),array是存储列表的变量。列表的值不一定要放在数组里,但是每个数组变量都一定包含一个列表。 数组或者列表的头一个元素是第0个。任何求值...
  • manhusl
  • manhusl
  • 2015年06月20日 19:21
  • 387

Usage of Array in Perl

一、列表 列表是包含在括号里的一序列的值,可以为任何数值,也可为空,如:(1, 5.3 , "hello" , 2),空列表:()。 注:只含有一个数值的列表(如:(43.2) )与该数值本身(即:4...

Polymorphism in Perl comparing with JAVA and C++

Polymorphism in Perlcomparing with JAVA and C++ Abstract In USD daily test automation, we used Per...

What's the difference between “local” and “my” in Perl

There are two kinds of variable scopes in Perl: Global variables: They reside in the current pa...
  • ThinkHY
  • ThinkHY
  • 2012年08月30日 12:55
  • 1427

Leetcode--Add to List 215. Kth Largest Element in an Array

题目Find the kth largest element in an unsorted array. Note that it is the kth largest element in the ...

D-Bus : Transmit a Data Array in Simple and Useful Form

In lots situation, One would send data via a simple data structure :  a byte array contain real data...

type conversion of array and pointer in C(1)


Divide and Conquer (1) -- Kth Largest Element in an Array,Different Ways to Add Parentheses

Kth Largest Element in an Array,Different Ways to Add Parentheses
  • dwt0317
  • dwt0317
  • 2017年01月12日 22:59
  • 109

Character String and Character String Array in C Programming

1. #include int main() { char b[] = {'R','O','H','E','\0','O','O','\0'}; char a[3] = {'H','E','...
您举报文章:List and Array in Perl