my @array = ( 1, 2, 3, 4, 5, 6 ); while (@array) { my $firstTotal = pop(@array); print "@array\n"; } output: 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 3、shift #!/usr/bin/perl ###<shift>### use strict; use warnings; my @array = ( 1, 2, 3, 4, 5, 6 );...
perl push an array to hash #!/usr/bin/perlusestrict;usewarnings;useData::Dumper;my@array=qw/fm1 fm2 fm3 fm4 fm5 fm6/;print"\n\@array: @array\n\n";my%hash;my$key1="gene1";my$key2="gene2";print"\$key1: $key1\n\$key2: $key2\n\n";my@array1 = @array[0..2];my...
序号 类型和描述 1 push (@ARRAY, LIST) 将列表的值放到数组的末尾 2 pop (@ARRAY) 弹出数组最后一个值,并返回它;当没有元素可弹出时,返回undef 3 shift (@ARRAY) 弹出数组第一个值,并返回它;数组的索引值也依次减一 4 unshift (@ARRAY, LIST) 将列表放在数组前面,并返回新数组的元素个数 ...
push:从数组的末尾加入元素。 pop :从数组的末尾取出元素 shift: 从数组的开头取出元素 unshift:从数组的开头加入元素 其应用具体如下: 1、push #!/usr/bin/perl use strict;use warnings; my @array = (); for ( my $i = 1 ; $i <= 5 ; ++$i ) { push @array, $i; print "@array\n";}...
1、push()、pop()和unshift()、shift() 这两组同为对数组的操作,并且会改变数组的本身的长度...
3.push ❞ #将list(列表)中的值添加到数组末尾 push@array,list; ❝ 4.unshift ❞ #将list(列表)中的值添加到数组开头,并返回新数组的元素个数 unshift@array,list; 「访问数组元素」 ❝ 1.任何求值得到数字的表达式都可用作下标,如...
数组末尾增加元素:push 数组末尾删除元素:pop 数组开头增加元素:unshift #数组开头删除元素:shift 颠倒...
除单个变量(Perl 称为 Scalar)之外,Perl 还有两种集合类型,分别是数组(Array,用@字符开头)和关联数组(Associative array,或者称为Hash,用%开头。类似 C++ 的 STL map 和 Python 的 Dictionary)。数组可以内含任意可变数目的变量。而Hash表,则可以在变量之间建立一一映射,就像字典一样,可以把不同的变量按照他们的逻...
# create a simple array @coins=("Quarter","Dime","Nickel"); print "1.\@coins =@coins\n"; # add one element at the end of the array push(@coins, "Penny"); print "2.\@coins =@coins\n"; # add one element at the beginning of the array ...
my @data1 = qw(one won); my @data2 = qw(two too to); push @data2, \@data1; push @data1, \@data2; # 将'[\@data1, \@data2]'冻结到'$frozen'中my $frozen = freeze [\@data1, \@data2]; # 解冻(恢复) my $array_all_ref = thaw($frozen); print Dumper($array_all_ref...