有人知道获取傀儡清单中数组的最后一个元素的巧妙方法吗?
现有代码如下:
class nginx {
define vhost {
#-----
# Init vars
#-----
$app_parts = split($name, '[_]')
# I can access any element using numeric notation
notify { "Element: ${app_parts[0]}": }
# How do I access the last element?
答案1
Arrays support negative indexing, with -1 being the final element of the array:
所以..
$foo = [ 'one', 'two', 'three', 'four', 'five' ]
notice( $foo[-1] )
# 'five'