You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes you want to return true or false, not a value which happens to be true or false. Usually this is to avoid the value being used for some undocumented purpose, or to avoid leaking private data which should not be available. Often the !! secret operator is used to "boolify" an expression.
For example...
# Accidentally returns the count of things.
sub has_things {
return scalar @things;
}
# Returns true or false.
sub has_things {
return !!@things;
}
Rather than use a secret operator, we could provide something like boolify to make the meaning more plain.
# Force it into scalar context so `boolify @things` works on the size of @things, not $things[0]
sub boolify($) { return !!$_[0] }
sub has_things {
return boolify @things;
}
The text was updated successfully, but these errors were encountered:
Sometimes you want to return true or false, not a value which happens to be true or false. Usually this is to avoid the value being used for some undocumented purpose, or to avoid leaking private data which should not be available. Often the
!!
secret operator is used to "boolify" an expression.For example...
Rather than use a secret operator, we could provide something like
boolify
to make the meaning more plain.The text was updated successfully, but these errors were encountered: