Neil is correct, of course, but if you start thinking in those terms, then 
you're still thinking like Cfengine is a programming language, and not a 
declarative language.  Why do you need a particular element of a list?  The 
idea behind lists is that you address all of the elements, either serially 
(with no break or next or continue or last statements) or as a whole.  You can 
get all of the indices if you want - but you can't select which you want.  As 
soon as you have that kind of decision mechanism, you introduce (the 
possibility, at least) of non-convergent promises.

-Dan

On Sep 5, 2011, at 12:49 AM, no-re...@cfengine.com wrote:

> Forum: CFEngine Help
> Subject: Re: Access single list element
> Author: sauer
> Link to topic: https://cfengine.com/forum/read.php?3,23314,23351#msg-23351
> 
> neilhwatson Wrote:
> -------------------------------------------------------
>> Is there a way to access a given element within a
>> list?  In Perl one might call
>> $list[0] to get the first element. I tried a few
>> variations of that in CF but
>> nothing seemed to work.  I thought there was a
>> thread about this some time ago
>> but, I can seem to find it.
> 
> That'd be an array then, not a list. ;)  I'd probably solve the problem by 
> doing something like
> "listtoarray[$(list)]" string => "$(list)"
> and then referencing elements from listtoarray.  And then I'd be compelled to 
> say twelve Hail Marys afterwards to make up for copying the whole list to an 
> array just to get to a single element which was already basically in an 
> array. :)
> 
> There's probably something you could do with a combination of join, split, 
> and grep as well if you feel more adventurous.
> 
> _______________________________________________
> Help-cfengine mailing list
> Help-cfengine@cfengine.org
> https://cfengine.org/mailman/listinfo/help-cfengine

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to