Puppet - 拆分 - 获取可变大小数组的最后一个元素

Mik*_*ell 3 puppet

任何人都知道一种巧妙的方法来获取人偶清单中数组的最后一个元素?

现有代码如下所示:

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?
Run Code Online (Sandbox Code Playgroud)

Tom*_*nor 6

Arrays support negative indexing, with -1 being the final element of the array:
Run Code Online (Sandbox Code Playgroud)

文档链接

所以..

$foo = [ 'one', 'two', 'three', 'four', 'five' ]
notice( $foo[-1] )
# 'five'
Run Code Online (Sandbox Code Playgroud)