The quick answer is "you don't".

The longer answer is: an slist (or ilist or rlist) can only be iterated over
in it's entirety by referencing the list as a scalar (and then cfengine
iterates over the whole list automagically).  You can index an array (which
is what 'foo' is in your example), but arrays are not iterable.  However, you
can create an slist of all the keys of 'foo' with getindices() - and thus can
iterate over that slist to look at all elements of the array by key...

The '[1]' in your example won't work, because slists are not indexable.  But
you *could* say:

        "foo[keyA][1]" string => "valA";
        "foo[keyA][2]" string => "valB";
        "foo[keyB][1]" string => "valC";
        "foo[keyB][2]" string => "valD";
        ...

That would create an "array of arrays" (kinda sorta :-), and arrays *are*
indexable (but not iterable).

-Dan

> Hi
> 
> Apologies if I'm a bit late to the party on this subject, but how do you
> reference a specific sub-element of an slist that is a value part of an
> associative array? So far all the doco I've read is a bit light on more
> "advanced" uses of arrays.
> 
> For example, I have the following var defined:
> 
>    "foo[keyA]" slist => {"valA","valB"};
>    "foo[keyB]" slist => {"valC","valD"};
>    "foo[keyC]" slist => {"valE","valF"};
> 
> I would like to perform the following:
> 
>    "bar[key]" string => "$(foo[$(dynamic_value)][1])";
> 
> where `dynamic_value` is the output of an execresult. Is this possible or
> am I missing something obvious here? Referencing by scalar for the
> purposes of iteration doesn't seem to offer much help here, assuming I
> understand it correctly.
> 
> Thank you
> 
> Steve
> 
> _______________________________________________
> 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