List and Array in Perl
2013-12-02 16:17
281 查看
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
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
相关文章推荐
- scalar and list context in Perl
- array linkedlist in divide and ..
- 81. Search in Rotated Sorted Array II (Array; Divide-and-Conquer)
- HowTo: ListView, Adapter, getView and different list items’ layouts in one ListView
- #1055 - Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this i
- Difference and using: Array,List,Map
- What's the difference between “local” and “my” in Perl
- 215. Kth Largest Element in an Array(divide and conquer)
- Polymorphism in Perl comparing with JAVA and C++
- type conversion of array and pointer in C(2)
- warning: do not list domain haha.com.cn in BOTH mydestination and virtual_mailbox_domains
- Building Tag Clouds in Perl and PHP
- Linq to array and linq to list
- HowTo: ListView, Adapter, getView and different list items’ layouts in one ListView
- List of free and open source operating systems (In alphabetic order, 345)
- How to use next and last in Perl
- Populate A List Item With Record Group In Oracle Forms Using Populate_List And Create_Group_From_Query Command
- Spring Form Tags - How to use Text Box, Radio Button, Check Box and Drop Down List in Spring
- differences between List and Set interface in point format
- Array of country list in PHP with Zend Framework