我想在Perl中实现一个堆栈,我有一个数组。我想推动阵列上的项目,弹出项目并打印出如下新阵列:“1,2,3,5,6为什么我的push和pop方法不起作用?
我该怎么做?我的代码只是将数字6添加到该阵列的顶部。
#!usr/bin/perl
@array = 1..5;
push @array, 6; #Push the number 6 into the array
pop @array, 4; #Pop the number 4 out of the array
print "The array is now $array[-1].\n";
你期望'pop @array,4;'做什么? – hobbs
你没有严格使用,你没有使用警告。 – tchrist
您应该在开发Perl代码时始终启用警告。 – tadmc