{"id":7240,"date":"2022-12-20T19:35:57","date_gmt":"2022-12-20T22:35:57","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/mdkcommonvarious-man3\/"},"modified":"2022-12-20T19:35:57","modified_gmt":"2022-12-20T22:35:57","slug":"mdkcommonvarious-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/mdkcommonvarious-man3\/","title":{"rendered":"MDK::Common::Various (man3)"},"content":{"rendered":"<h1 align=\"center\">MDK::Common::Various<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#EXPORTS\">EXPORTS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">MDK::Common::Various \u2212 miscellaneous functions<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">use MDK::Common::Various qw(:all);<\/p>\n<h2>EXPORTS <a name=\"EXPORTS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">first( <small>LIST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">returns the first value. &#8220;first(XXX)&#8221; is an alternative for &#8220;((XXX)[0])&#8221;<\/p>\n<p style=\"margin-left:11%;\">second( <small>LIST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">returns the second value. &#8220;second(XXX)&#8221; is an alternative for &#8220;((XXX)[1])&#8221;<\/p>\n<p style=\"margin-left:11%;\">top( <small>LIST<\/small> )<\/p>\n<p style=\"margin-left:17%;\">returns the last value. &#8220;top(@l)&#8221; is an alternative for $l[$#l]<\/p>\n<p style=\"margin-left:11%;\">to_bool( <small>SCALAR<\/small> )<\/p>\n<p style=\"margin-left:17%;\">returns a value in { 0, 1 }<\/p>\n<p style=\"margin-left:11%;\">to_int( <small>STRING<\/small> )<\/p>\n<p style=\"margin-left:17%;\">extracts the number from the string. You could use directly &#8220;int &#8220;11 foo&#8221;&#8221;, but you\u2019ll get <i>Argument &#8220;11 foo&#8221; isn\u2019t numeric in int<\/i>. It also handles returns 11 for &#8220;foo 11 bar&#8221;<\/p>\n<p style=\"margin-left:11%;\">to_float( <small>STRING<\/small> )<\/p>\n<p style=\"margin-left:17%;\">extract a decimal number from the string<\/p>\n<p style=\"margin-left:11%;\">bool2text( <small>SCALAR<\/small> )<\/p>\n<p style=\"margin-left:17%;\">returns a value in { &#8220;true&#8221;, &#8220;false&#8221; }<\/p>\n<p style=\"margin-left:11%;\">bool2yesno( <small>SCALAR<\/small> )<\/p>\n<p style=\"margin-left:17%;\">returns a value in { &#8220;yes&#8221;, &#8220;no&#8221; }<\/p>\n<p style=\"margin-left:11%;\">text2bool( <small>STRING<\/small> )<\/p>\n<p style=\"margin-left:17%;\">inverse of &#8220;bool2text&#8221; and &#8220;bool2yesno&#8221;<\/p>\n<p style=\"margin-left:11%;\">chomp_( <small>STRING<\/small> )<\/p>\n<p style=\"margin-left:17%;\">non-mutable version of chomp: do not modify the argument, returns the chomp\u2019ed value. Also works on lists: &#8220;chomp_($a, $b)&#8221; is equivalent to &#8220;chomp($a) ; chomp($b) ; ($a,$b)&#8221;<\/p>\n<p style=\"margin-left:11%;\"><b>backtrace()<\/b><\/p>\n<p style=\"margin-left:17%;\">returns a string describing the backtrace. eg:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">sub g { print &#8220;oopsn&#8221;, backtrace() } <br \/> sub f { &#038;g } <br \/> f();<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">gives<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">oops <br \/> main::g() called from \/tmp\/t.pl:2 <br \/> main::f() called from \/tmp\/t.pl:4<\/p>\n<p style=\"margin-left:11%;\">internal_error( <small>STRING<\/small> )<\/p>\n<p style=\"margin-left:17%;\">another way to &#8220;die&#8221; with a nice error message and a backtrace<\/p>\n<p style=\"margin-left:11%;\"><b>noreturn()<\/b><\/p>\n<p style=\"margin-left:17%;\">use this to ensure nobody uses the return value of the function. eg:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">sub g { print &#8220;g calledn&#8221;; noreturn } <br \/> sub f { print &#8220;g returns &#8220;, g() } <br \/> f();<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">gives<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">test.pl:3: main::f() expects a value from main::g(), but main::g() doesn&#8217;t return any value<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">MDK::Common<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  MDK::Common::Various \u2212 miscellaneous functions <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3007,3566],"class_list":["post-7240","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-man3","tag-mdkcommonvarious"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7240","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=7240"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7240\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}