This library provides miscellaneous routines.
require "misc.pl"; %misc_date_strings = ... $result = &MiscCheckRule($_, $rule, $type); ($action, $what) = &MiscDoAction($action, $what); $newtext = &MiscTextWrap($text, $wrap, $prefix, $suffix, $keep_spaces); $result = &MiscDateFormat($fmt, $time, $msg_type); $mixed = &MiscUpperToMixed($upper); $upper = &MiscMixedToUpper($mixed);
MiscCheckRule checks a rule for a value $_. If an execution error is detected, an appropriate error is output. The result of the code executed is returned as result. If rule is an empty string, type is used to lookup a default rule for that type, if any. If rule is still an empty string, 1 is returned.
MiscDoAction executes a block of Perl code (action). If an execution error is detected, an appropriate error is output using what to name the block of code that failed. The result of the code executed is returned as result. action is only executed if it exists. If it does not, 1 is returned.
MiscTextWrap wraps a text string at a margin given by wrap. prefix is the string to begin each wrapped line. suffix is the string to terminate each wrapped line.
- prefix is not added to the first line
- suffix is not added to the last line
- wrap includes prefix but excludes suffix
MiscDateFormat formats a date-time value. fmt is a string containing the symbols below.
|$day||day number in month||6 or 22|
|$day0||day number in month zero-padded||06 or 22|
|$smonth||abbreviated month name||Jan|
|$monthnum||month number (1..12)||6 or 12|
|$monthnum0||month number zero-padded (01..12)||06 or 12|
|$sweekday||abbreviated weekday name||Mon|
|$hour||hour (1..24)||6 or 14|
|$hour0||hour zero-padded (01..24)||06 or 14|
|$shour||hour (1..12)||6 or 12|
|$shour0||hour zero-padded (01..12)||06 or 12|
|$ampm||am or pm||am|
|$AMPM||AM or PM||PM|
|$minute||minute (0..59)||0 or 42|
|$minute0||minute zero-padded (00..59)||00 or 42|
|$second||second (0..59)||0 or 42|
|$second0||second zero-padded (00..59)||00 or 42|
time is a number of seconds since January 1, 1970. msg_type is the type of message, if any, to output when a bad format is found.
MiscUpperToMixed converts a name in an uppercase form (e.g. MY_STRING) to a mixed-case form (e.g. MyString).
MiscMixedToUpper converts a name in a mixed-case form (e.g. MyString) to an uppercase form (e.g. MY_STRING).