NAME
MDK::Common::Various - miscellaneous functions
SYNOPSIS
use MDK::Common::Various qw(:all);
EXPORTS
- first(LIST)
-
returns the first value.
first(XXX)
is an alternative for((XXX)[0])
- second(LIST)
-
returns the second value.
second(XXX)
is an alternative for((XXX)[1])
- top(LIST)
-
returns the last value.
top(@l)
is an alternative for$l[$#l]
- to_bool(SCALAR)
-
returns a value in { 0, 1 }
- to_int(STRING)
-
extracts the number from the string. You could use directly
int "11 foo"
, but you'll get Argument "11 foo" isn't numeric in int. It also handles returns 11 for"foo 11 bar"
- to_float(STRING)
-
extract a decimal number from the string
- bool2text(SCALAR)
-
returns a value in { "true", "false" }
- bool2yesno(SCALAR)
-
returns a value in { "yes", "no" }
- text2bool(STRING)
-
inverse of
bool2text
andbool2yesno
- chomp_(STRING)
-
non-mutable version of chomp: do not modify the argument, returns the chomp'ed value. Also works on lists:
chomp_($a, $b)
is equivalent tochomp($a) ; chomp($b) ; ($a,$b)
- backtrace()
-
returns a string describing the backtrace. eg:
sub g { print "oops\n", backtrace() } sub f { &g } f();
gives
oops main::g() called from /tmp/t.pl:2 main::f() called from /tmp/t.pl:4
- internal_error(STRING)
-
another way to
die
with a nice error message and a backtrace - noreturn()
-
use this to ensure nobody uses the return value of the function. eg:
sub g { print "g called\n"; noreturn } sub f { print "g returns ", g() } f();
gives
test.pl:3: main::f() expects a value from main::g(), but main::g() doesn't return any value