Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert array to comma separated string in Puppet 2.7

Tags:

puppet

I am using Puppet 2.7 and I need to convert an array to comma separated list.

$hosts_fqdn= ['host1','host2','host3']

And I need to convert it to desired result: 'host1,host2,host3'

I guess that Puppet 3.2 offers lambda expression - reduce. But unfortunately that is not possible with 2.7.

like image 618
jaksky Avatar asked Aug 30 '13 06:08

jaksky


People also ask

How can I convert an array to comma separated string?

To convert an array to a comma-separated string, call the join() method on the array, passing it a string containing a comma as a parameter. The join method returns a string containing all array elements joined by the provided separator.

How do you add comma separated values in a string array in Java?

The simplest way to convert an array to comma separated String is to create a StringBuilder, iterate through the array, and add each element of the array into StringBuilder after appending the comma.

How do I store a list of integers separated by comma entered by a user inside an array in Java?

List<String> items = Arrays. asList(commaSeparated. split(",")); That should work for you.

Which of the following methods is an internal implementation of an array that returns a comma separated list of items?

Arrays have their own implementation of toString method that returns a comma-separated list of elements.


1 Answers

Function join from puppetlabs/stdlib:

join($hosts_fqdn,',')
like image 114
jaksky Avatar answered Sep 21 '22 21:09

jaksky