A+B: Difference between revisions
CFEngine example
(1-based index) |
(CFEngine example) |
||
Line 1,848:
}
}</syntaxhighlight>
=={{header|CFEngine}}==
There is no concept of CFEngine policy reading from stdin so I will read from a file.
<syntaxhighlight lang="cfengine">
bundle agent main
{
vars:
"line_count" int => readintarray(
"input",
"${this.promise_dirname}${const.dirsep}input.txt",
"#[^\n]*",
" ",
"inf",
"inf"
);
"indices" slist => getindices( "input" );
reports:
"${with}" with => format( "%d", eval( "${input[${indices}][0]} + ${input[${indices}][1]}" ));
DEBUG::
"line_count is ${line_count}";
"input is ${with}" with => storejson( "input" );
"input[${indices}] is ${with}" with => storejson( "input[${indices}]" );
}
</syntaxhighlight>
with input.txt next to sum.cf (above policy file), run cf-agent -KIf ./sum.cf and output will be
R: 5
R: 4
The "R:" prefix is for a report promise and the only way to output to stdout with policy.
You could also output to a file I suppose.
=={{header|Clojure}}==
|