no-re...@cfengine.com a écrit :
>Forum: CFEngine Help
>Subject: Slists and looping
>Author: random
>Link to topic:
>https://cfengine.com/forum/read.php?3,24160,24160#msg-24160
>
>I'm messing around with some simple looping over slists and ran into a
>problem with the code below. It appears that cfengine isn't recursive
>when looping and won't expand my slists as I would expect. Is there
>any work around for this or am I just doing it wrong?
>
>Thanks!
>
>
>body common control {
> bundlesequence => {
> "test"
> };
>
> inputs => {
> "cfengine_stdlib.cf"
> };
>}
>
>bundle agent test {
> vars:
> "test1" slist => { "one", "two", "three" };
> "test2" slist => { "three", "four", "five" };
> "test3" slist => { "athree", "afour", "afive" };
>
> "members" slist => { @(test1), @(test3) };
>
> "members" slist => { @(test2), @(test3) };
>
> "userlist" slist => getindices("members");
>
> reports:
> linux::
> "User: $(userlist) Element: $(members[$(userlist)])";
>
>}
You appear to be confusing lists and arrays. The arrayname[key] notation has no
significance for lists, which is why this example doesn't work as you expect.
Remember, arrays are like hashmaps, and can store key => value pairs. They are
defined like this:
"arrayname[key1]" => "value1";
Lists are one dimension only. Lists are useful to store all the keys in an
array ... Using indices. :-)
Hope this helps,
Jonathan
>
>
>_______________________________________________
>Help-cfengine mailing list
>Help-cfengine@cfengine.org
>https://cfengine.org/mailman/listinfo/help-cfengine
--
Envoyé de mon téléphone Android avec K-9 Mail. Excusez la brièveté.
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine