Your approach will not work. One of the core characteristics of Puppet variables is that once assigned, their values never change.
I haven't played much with the future parser, but since you're looking that direction, I think it can do the job for you. Start by replacing your 'case' statement with a hash declaration:
$group_attributes = {
'MAMMAL' => ['horse', 'cow', 'dog'],
'REPTILE' => ['gator', 'frog'],
'BIRD' => ['finch', 'chicken']
}
The task you want to perform is essentially to transform / map server groups to attibutes, so the future parser's map() function seems a good candidate. The only extra trick is that you want to combine the results of each mapping, but that should be straightforward if none of the elements 'horse', 'cow', etc. are themselves arrays IRL. Something along these lines ought to do the job:
$foo = flatten(
split($servergroup, ',').map |$group_name| {
$group_attributes[$group_name]
}
)
Note in particular that there is only one assignment to variable $foo. Note also that it will work equally well for servers belonging to one group and those belonging to many.
If you are comfortable with using the future parser, then I think that's a pretty good and effective application, much easier to apply to the merging problem than hiera would be. There is still a role in this for hiera, however: it would be better to store the $group_attributes data in an external file, and getting the data from there into Puppet is Hiera's bread & butter.
John