How to index into array from a function

64 views
Skip to first unread message

Despite

unread,
Aug 2, 2012, 10:30:48 AM8/2/12
to puppet...@googlegroups.com
Is there a clean way to index into an array returned by a function?  When I try to do it directly, I get a parser error.  I have to assign the array to a new variable and index that.

# This fails
$dc = split($domain,'[.]')[0]

# This works
$split_domain = split($domain,'[.]')
$dc = $split_domain[0]

I guess it really doesn't matter, it's just annoying and breaks my expectations.
Message has been deleted

jcbollinger

unread,
Aug 3, 2012, 12:10:07 PM8/3/12
to puppet...@googlegroups.com

I've seen another area recently where the return values of functions cannot be used directly as an ordinary value (they cannot be used as resource titles).  I suspect that the parser just doesn't anticipate those cases, but perhaps there's something about the grammar or implementation that makes such cases hard.  I encourage you to file a feature request.


John

Reply all
Reply to author
Forward
0 new messages