On Mon, Apr 13, 2015 at 11:10 AM, jcbollinger <[email protected]> wrote: > You're already generating a compound search key (although it's not strictly > necessary for what you're doing so far); a reasonable solution would be a > compound sort key that captures the IP address (if any) as the first part, > and the rest of the hash key as a second part. Here's a way to approach it > with the help of a Ruby regex: > > <% > require 'ipaddr' > if @bind > @bind.sort_by { |address_port, bind_params| > md = /^((\d+)\.(\d+)\.(\d+)\.(\d+))?(.*)/.match(address_port) > [ (md[1] ? md[2..5].inject(0){ |addr, octet| (addr << 8) + octet.to_i } > : -1), md[6] ] > }.map do |address_port, bind_params| > -%> > bind <%= address_port -%> <%= Array(bind_params).join(" ") %> > <% > end > else > -%> > > > In the sort_by() block, variable 'md' captures the match data for matching > the given regex against the 'address_port' string. The regex will match any > string; the important part is the capturing groups. If the string starts > with a dotted-quad address then the whole address is captured as group 1, > and the segments are captured as groups 2 - 5. Whatever is not matched as a > dotted-quad address is always captured as group 6. The dotted-quad match is > all-or-nothing; either four segments will be captured or none. The sort key > is then formed as a two-element array: the first element is -1 if no address > is given, else the 4-byte integer IP address, and the second element is the > string tail.
John, That looks great! I'll give that a try. (Though possibly after a delay... I have some higher priority issues on my plate) Tom -- Email: [email protected] Work: [email protected] Skype: YesThatTom Blog: http://EverythingSysadmin.com -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAHVFxg%3D9VQY4NUOSauTeaUzMfwaYjHKHcUua%2BVK27Jh6U31m7w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
