FAQ
I use this:

<%= relay_destinations.join(',') %>

On Sep 10, 2012, at 1:22 PM, JeremyCampbell wrote:

I need to produce a line in a config file in the format x = "ip1,ip2,ip3"

I am using the method below to sort the hash before iterating over it. However, as you can see there will always be a final comma which breaks the app that uses this config file. Does anyone know how I could remove the final comma?

ipv4_bind_addresses = "<% routes.sort_by {|key, v| key}.each do |key, v| -%><%= net %>.<%= v['pubnet'] %>.1,<% end -%>"


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/DsCB3zXfHk0J.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Search Discussions

  • JeremyCampbell at Sep 10, 2012 at 5:28 pm
    I need to produce a line in a config file in the format x = "ip1,ip2,ip3"

    I am using the method below to sort the hash before iterating over it.
    However, as you can see there will always be a final comma which breaks the
    app that uses this config file. Does anyone know how I could remove the
    final comma?

    ipv4_bind_addresses = "<% routes.sort_by {|key, v| key}.each do |key, v|
    -%><%= net %>.<%= v['pubnet'] %>.1,<% end -%>"

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/DsCB3zXfHk0J.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • R.I.Pienaar at Sep 10, 2012 at 5:28 pm

    ----- Original Message -----
    From: "JeremyCampbell" <jeremycampbell87@gmail.com>
    To: puppet-users@googlegroups.com
    Sent: Monday, September 10, 2012 6:22:17 PM
    Subject: [Puppet Users] How to remove last comma when iterating through hash in erb template

    I need to produce a line in a config file in the format x =
    "ip1,ip2,ip3"

    I am using the method below to sort the hash before iterating over
    it. However, as you can see there will always be a final comma which
    breaks the app that uses this config file. Does anyone know how I
    could remove the final comma?

    ipv4_bind_addresses = "<% routes.sort_by {|key, v| key}.each do |key,
    v| -%><%= net %>.<%= v['pubnet'] %>.1,<% end -%>"

    the key is to go via an array and then use join:

    ipv4_bind_addresses = "<%= routes.sort_by {|key, v| key}.map{|key, v| '%s.%s.1' % [net, v['pubnet']]}.join(',') -%>"

    not seeing your data so it's hard to test if this will work for you but
    the 'map' method takes the block and returns an array of each iteration
    of the block - strings in this case. Calling join on the strings will
    then avoid the trailing ,

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • JeremyCampbell at Sep 11, 2012 at 7:32 am

    On Monday, September 10, 2012 7:28:58 PM UTC+2, R.I. Pienaar wrote:

    ----- Original Message -----
    From: "JeremyCampbell" <jeremyca...@gmail.com <javascript:>>
    To: puppet...@googlegroups.com <javascript:>
    Sent: Monday, September 10, 2012 6:22:17 PM
    Subject: [Puppet Users] How to remove last comma when iterating through
    hash in erb template
    I need to produce a line in a config file in the format x =
    "ip1,ip2,ip3"

    I am using the method below to sort the hash before iterating over
    it. However, as you can see there will always be a final comma which
    breaks the app that uses this config file. Does anyone know how I
    could remove the final comma?

    ipv4_bind_addresses = "<% routes.sort_by {|key, v| key}.each do |key,
    v| -%><%= net %>.<%= v['pubnet'] %>.1,<% end -%>"

    the key is to go via an array and then use join:

    ipv4_bind_addresses = "<%= routes.sort_by {|key, v| key}.map{|key, v|
    '%s.%s.1' % [net, v['pubnet']]}.join(',') -%>"

    not seeing your data so it's hard to test if this will work for you but
    the 'map' method takes the block and returns an array of each iteration
    of the block - strings in this case. Calling join on the strings will
    then avoid the trailing ,
    Thats worked perfectly! Dankie meneer!
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/ORDDDpMGpeIJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedSep 10, '12 at 5:24p
activeSep 11, '12 at 7:32a
posts4
users3
websitepuppetlabs.com

People

Translate

site design / logo © 2022 Grokbase