Perl 免费提供许多数据结构,这些数据结构在其他编程语言里是需要你自己制作的。
比如那些计算机 科学的新芽们都需要学习的堆栈和队列在 Perl 里都只是数组
pop:
pop 操作将数组的最后一个元素取出并返回:
Vsftp:/root/perl/5# cat a1.pl
my @arr=qw/a b c d e f g/;
print "\@arr is @arr\n";
pop @arr;
print "\@arr is @arr\n";
Vsftp:/root/perl/5# perl a1.pl
@arr is a b c d e f g
@arr is a b c d e f
push,它可以将一个元素(或者一列元素)加在数组的末尾:
Vsftp:/root/perl/5# cat a1.pl
my @arr=qw/a b c d e f g/;
print "\@arr is @arr\n";
pop @arr;
print "\@arr is @arr\n";
push (@arr,'xxyy');
print "\@arr is @arr\n";
Vsftp:/root/perl/5# perl a1.pl
@arr is a b c d e f g
@arr is a b c d e f
@arr is a b c d e f xxyy
shift 拿掉数组最左边的一个值
Vsftp:/root/perl/5# cat a2.pl
my @arr=qw/a b c d e f g/;
print "\@arr is @arr\n";
shift @arr;
print "\@arr is @arr\n";
Vsftp:/root/perl/5# perl
数组的数组
最新推荐文章于 2024-02-23 20:43:17 发布