Issue #3300 has been updated by Henrik Lindberg.
Status changed from Re-opened to Rejected
When using --parser future (available since 3.2) there is new functionality
that makes this much easier. Here is an example:
<pre>
$a = $b = $c = 1
$f = 2
$val = ([$a, $b, $c, $d, $e, $f].reduce([]) |$memo, $x| { if $x == undef {
$memo } else {$memo << $x} })
notice $val
</pre>
The result is `[1,1,1,2]` (i.e. the undefined variables are skipped).
In future parser there is support for concatenation/merge of array/hash using
'+' (to a new variable) and append to array using '<<'. In the example, the new
reduce function reduces the array (with some positions being undef) to a new
array.
Combined with other iterative functions (each, collect, select/reject) this
should give enough power to transform the data into the wanted shape.
Variables are immutable in the Puppet Language, and thus the += operator will
never be able to mutate an existing variable. Hence the earlier rejection of
this issue (and I am now rejecting the re-open).
The 'future parser' is most likely going to be the 'current parser' in puppet
4, it remains experimental until then (but should be fully functional).
----------------------------------------
Feature #3300: appending to variables already defined in this scope
https://projects.puppetlabs.com/issues/3300#change-96509
* Author: Xavier Delaruelle
* Status: Rejected
* Priority: Normal
* Assignee: Nigel Kersten
* Category: parser
* Target version:
* Affected Puppet version: 0.25.4
* Keywords:
* Branch:
----------------------------------------
Hello,
As mentioned in the doc, it is possible since 0.24.6 to append to variables
already defined in a different scope. But when appending to a variable already
defined in the scope, like in the following example:
<pre>
define foo ($val) {
$bar = [ 'val1', 'val2' ]
if $val != '' {
$bar += [ $val ]
}
}
</pre>
puppet returns the following error:
<pre>
Cannot append, variable bar is defined in this scope at /tmp/test.pp:8 on node
host
</pre>
Appending to variables already defined in the scope could be useful when we
want to adapt the behavior of a class or a define depending of variable values.
--
You have received this notification because you have either subscribed to it,
or are involved in it.
To change your notification preferences, please click here:
http://projects.puppetlabs.com/my/account
--
You received this message because you are subscribed to the Google Groups
"Puppet Bugs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/groups/opt_out.