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


In reply to Re: preserve array from getting re-initilize by TomDLux
in thread preserve array from getting re-initilize by tart

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.