NAME

Misc.pm - miscellaneous functions I find useful


sub debug_start($;@)

Prints out useful diagnostic information when entering a function. The first argument is the filehandle to print to, the second is the arguments to the function it is called from.

Try calling it like this from class methods: Misc::debug_start($debug_fh, @_[ 1 .. $#_ ]) if defined $debug and $debug;


sub debug_end($;$)

Prints out useful diagnostic information right before exiting a function. Assumes that the function will exit on the next line. Pass it the filehandle to print to, and the return value of the function.


stack_trace()

Return an array containing filename, function, and line information about each function currently on the stack.


xdie(;@)

Exit by passing the elements of the passed array to die(), if the last element in the passed array does not end with a newline (or no arguments are passed), also print out a stack trace after printing the other passed arguments.


xsprintf($string) : $string

Takes a format string in which the following strings are treated specially:

%p

the package name

%f

the filename name

%l

the line

%s

the subroutine name

%S

the package name and the subroutine name (package::subroutine)

You can escape a %C string by %%C.

Returns the string with the %C sequences transformed.


bad_args($$)

I often use this to at the start of my functions like this:

 @_ == 1 or @_ == 2 Misc::bad_args("1 or 2", scalar @_);

to perform a small sanity check on the number of arguments passed.