It's called a closure, and it's perfectly valid way of doing things, though 'state' is the new, improved way.
But I'm confused by what this routine is supposed to do. Considering you print out the time and message, if $configHR->{VERBOSE} is true, I'm guessing this is a logging routine.
But you've rather overloaded the term verbose ... It's the name of the routine, the tag of the only postion of the config hashref you look at, and a value for the info field.
Personally, I would go for a small inline package named logger' witha constructor, a print() method and a flush() method. The constructor takes and arg, 'mode', and sets a 'cached' attribute if mode is 'cached'. print() caches the formatted message is caching is enabled, otherwise prints it.
use POSIX qw(strftime);
my $time = POSIX::strftime( "%T", localtime)
will give you the hours, minutes seconds. As for truncating the message
my $msg = substr( $msg, 0, 50 ) . '-'
if 50 < length $msg;
If you wanted to be fancy, the constructor could return a caching subclass or a printing subclass instance, depending on the arg. But a single if() is not too painful.
--
TTTATCGGTCGTTATATAGATGTTTGCA
|