...since localtime is getting called again...

Nothing you have shown supports this claim. You've shown a line of code that assigns the result of the localtime() function to the $localtime variable, but not where it exists in the code. So, we have no idea what execution paths may or may not cause that assignment to take place. Ergo, there is no reason for anyone to believe that the $localtime variable ever changes its value.

To me, it sounds like you're doing something like this:

our $foo = 5; print "foo is $foo\n"; print "foo is $foo\n";
and wondering why it doesn't output
foo is 5
foo is 6
In this example, $foo clearly does not change its value between the two calls to print. Likewise, in your example, it appears that $localtime does not change its value. And this is as it should be because there is nothing magical about a variable named $localtime. You could have named it $foo as I did and you would get the same results.

So ... move the assignment to $localtime such that it's inside your output subroutine and gets executed each time the subroutine is executed, or use one of the many suggestions given in this thread that obviate the need for an extra variable.

duff-washing-his-hands-on-this-thread


In reply to Re^5: Localtime Updating by duff
in thread Localtime Updating by Anonymous Monk

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.