Forum: CFEngine Help Subject: Re: CFEngine Help: Slists and looping Author: random Link to topic: https://cfengine.com/forum/read.php?3,24179,24195#msg-24195
Jonathan Clarke Wrote: ------------------------------------------------------- > 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 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" => "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-cfengi > ne > > -- > 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-cfengin > e I just realized that my above code snippet was incorrect due to the forum trying to do something with my brackets. http://pastebin.com/r3FjdtVv Based on that code I'd expect that variable expansion would work, but it doesn't. Is this an oversight or by design to prevent an infinite loop or am I still missing something? _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine