Issue #3300 has been updated by Roman BarczyĆski.
Status changed from Rejected to Re-opened
Stronger use case:
<pre>
define foo ($bar, $baz) {
if ($bar != '') and ($baz != '') {
$val = [ 'a', 'b', $bar, $baz ]
} elsif $bar != '' {
$val = [ 'a', 'b', $bar ]
} elsif $baz != '' {
$val = [ 'a', 'b', $baz ]
} else {
$val = [ 'a', 'b' ];
}
}
</pre>
now imagine:
<pre>
define foo ($v1, $v2, $v3, $v4, $v5) {
[nightmare of ifs]
}
</pre>
vs 5x:
<pre>
if $v1 != 'something {
$val += $v1
}
</pre>
you wouldnt really find it much simpler?
----------------------------------------
Feature #3300: appending to variables already defined in this scope
https://projects.puppetlabs.com/issues/3300#change-87618
* Author: Xavier Delaruelle
* Status: Re-opened
* 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.