Perl数组unshift()函数教程

Perl's unshift() function is used to add value or values onto the beginning of an array (prepend), which increases the number of elements. The new values then become the first elements in the array. It returns the new total number of elements in the array. It's easy to confuse this function with push(), which adds elements to the end of an array.

Perl的unshift()函数用于将一个或多个值添加到数组的开头(前置),这会增加元素的数量。 然后,新值将成为数组中的第一个元素。 它返回数组中新的元素总数。 将此函数与push()混淆很容易,后者会将元素添加到数组的末尾。

Picture a row of numbered boxes, going from left to right. The unshift() function would add the new value or values on to the left side of the array, and increase the elements. In the examples, the value of @myNames becomes ('Larry', 'Curly', 'Moe').

为从左到右的行编号的框图片。 unshift()函数将在数组的左侧添加一个或多个新值,并增加元素。 在示例中,@ myNames的值变为(“ Larry”,“ Curly”,“ Moe”)。

The array can also be thought of as a stack—picture a stack of numbered boxes, starting with 0 on the top and increasing as it goes down. The unshift() function would add the value to the top of the stack, and increase the overall size of the stack.

也可以将数组视为一个堆栈,即一个由数字框组成的堆栈,从顶部的0开始,向下逐渐增加。 unshift()函数会将值添加到堆栈顶部,并增加堆栈的整体大小。

You can unshift() multiple values onto the array directly:

您可以将多个值直接unshift()到数组上:

Or by unshift()-ing an array:

或者通过unshift()-数组:

翻译自: https://www.thoughtco.com/perl-array-unshift-function-quick-tutorial-2641154

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值