-
Disclaimer: if this post/place is going to be removed let me/us users know first so we have the chance to post the content elsewhere for other puppet users. At the moment on the systems there is 4.10 available. Now in some cases we have the possibility to use functions from modules, like standardlib, but if possible I would like to avoid to rely too much on extra things that may change/may be unavailable in some circumstances (partial installations, puppet apply, modules that may avoid using other modules, etc..) Thus I have a fact that is an Hash, say With What if I do not use it? The best replacement I could identify, using the manual, is:
It seems to work and I do not find it that bad considering that it saves the dependency on a module. Is there anything better? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
from https://puppetcommunity.slack.com/archives/C0W298S9G/p1611326656098700 Yury B.How about if Pierfrancesco A.true (duh that was obvious, thank you!) , that would do it too! I want a "not empty" thus maybe something like: Yury B.
|
Beta Was this translation helpful? Give feedback.
-
PierfrancescoI was thinking, could it be that helindbethe first is false if, and only if the value is a hash and is empty, and true for all other values. (edited) What you want to use depends on what you really want to test for. The If you want to also ignore hashes that does not have Scalar key and Data values then do use PierDidn't know that I could simply use Hash[1] or Collection[1] (reading the 4.10 manual it seemed that I needed to give two values first then the min size) And I also didn't know that empty (that should be also in stdlib) is true also for undef. That is a tad less safer in my case. |
Beta Was this translation helpful? Give feedback.
Pierfrancesco
I was thinking, could it be that
if $fact['xxx'] != {}
is true also if the fact is undef ? (same for
if (! $fact['xxx'] == {}
)and thus
Hash[Scalar, Data, 1]
is safer?New
helindbe
the first is false if, and only if the value is a hash and is empty, and true for all other values. (edited)
the second is the same
What you want to use depends on what you really want to test for. The
empty()
function is true for empty array, hash, string, and for undef. If you are interested more strictly in an empty array or hash, you can use=~ Collection[0,0]
(empty) or=~ Collection[1]
(at least one - i.e. not empty).You can also use
Hash[0,0]
for empty hash.If you want to also ignore has…