Last active
August 29, 2015 14:03
-
-
Save runswithd6s/ef926f56b5c9e473324a to your computer and use it in GitHub Desktop.
puppetlabs/stdlib and delete on undef elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$array1 = undef | |
$array2 = ['a','b','c'] | |
$array3 = [$array1, $array2] | |
$flat = flatten([$array3]) | |
$pruned = delete($flat,undef) | |
$plist = join($pruned,',') | |
notice("Pruned array contains ${plist}") | |
# Expected Result - order not guaranteed | |
# "Pruned array contains a,b,c" | |
# Actual Results - order not guaranteed | |
# "Pruned array contains a,b,c,undef" | |
# The actual code snippet that is failing for me is | |
if $hostgroups and is_array($hostgroups) { | |
$prune_undef = delete($hostgroups,undef) | |
$prune_undef_str = delete($prune_undef,'undef') | |
$hlist = join($prune_undef_str,',') | |
} elsif $hostgroups { | |
notice("Received hostgroups as a string") | |
$hlist = $hostgroups | |
} | |
notice("Hostgroups to apply for ${host_name} are ${hlist}") | |
# I still get a list that includes the string "undef" in the array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this calls for adding a function called 'append'