MDK::Common::Various - miscellaneous functions
use MDK::Common::Various qw(:all);
returns the first value. first(XXX) is an alternative for ((XXX)[0])
first(XXX)
((XXX)[0])
returns the second value. second(XXX) is an alternative for ((XXX)[1])
second(XXX)
((XXX)[1])
returns the last value. top(@l) is an alternative for $l[$#l]
top(@l)
$l[$#l]
returns a value in { 0, 1 }
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"
int "11 foo"
"foo 11 bar"
extract a decimal number from the string
returns a value in { "true", "false" }
returns a value in { "yes", "no" }
inverse of bool2text and bool2yesno
bool2text
bool2yesno
non-mutable version of chomp: do not modify the argument, returns the chomp'ed value. Also works on lists: chomp_($a, $b) is equivalent to chomp($a) ; chomp($b) ; ($a,$b)
chomp_($a, $b)
chomp($a) ; chomp($b) ; ($a,$b)
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
another way to die with a nice error message and a backtrace
die
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();
test.pl:3: main::f() expects a value from main::g(), but main::g() doesn't return any value
MDK::Common
To install MDK::Common, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MDK::Common
CPAN shell
perl -MCPAN -e shell install MDK::Common
For more information on module installation, please visit the detailed CPAN module installation guide.