Re: [Puppet Users] How to iterate over an array? (with a counter)

James Patterson
Thu, 21 Jun 2012 06:31:58 -0000

On Wed, Jun 20, 2012, at 10:42 PM, R.I.Pienaar wrote:
>
>
> ----- Original Message -----
> > From: "James Patterson" <jamespatterson@operamail.com>
> > To: puppet-users@googlegroups.com
> > Sent: Wednesday, June 20, 2012 10:39:02 PM
> > Subject: [Puppet Users] How to iterate over an array? (with a counter)
> >
> > Given an array, I''d like to iterate over it with a counter to
produce
> > something like this from a template:
> >
> > foo.0 = ARRAYVALUE0
> > foo.1 = ARRAYVALUE1
> > foo.2 = ARRAYVALUE2
> >
> > (where ARRAYVALUEn is replaced by the value, and the foo.n is
> > incremented for each value)
> >
> > The puppet templates support iteration, but I don''t see how
to also
> > increment a counter to get the behaviour above? Is this possible?
> > Thanks.
>
> array.each_with_index do |item, index|
>    ...
> end
>
> item will be each item and index will increment from 0 upward
>

Excellent stuff! Just what I wanted!

If I wanted to sort numerically, backwards, skip numbers, do ($i=0;
$i<100; $i+2), etc, where should I read about that?

Thanks.

--
http://www.fastmail.fm - Does exactly what it says on the tin