Hi Monks!
I have a module that creates log files and uses localtime to get the time for the logs. My question is when I try to call this subroutine from the module from inside of a loop, the time from localtime keeps the same, I think that the call should happen on every interaction of the loop, creating a different time stamp for every line printed on this log file, instead all the lines have the same time as the first line created. Here is the example:

This is part of the code inside the module:
sub LOGGIN { .... open(LOG, ">>$log") or croak "Unable to append to $log: $!"; print LOG "[$localtime] $log : @data \n"; close LOG or die "Cannot close log file:: $log : $!\n"; .... }


Now here, I am calling it into my code, everything it's fine but when I look at the log lines:
#test code my $i=0; for (my $count=1; $count<11; $count++) { $i++; app_log($log,"Loading transac from \$file - $1"); print "cool<br>"; }


The times are all the same:
[Fri Feb 14 09:28:30 2005] test_of_log.txt : Loading transac [Fri Feb 14 09:28:30 2005] test_of_log.txt : Loading transac [Fri Feb 14 09:28:30 2005] test_of_log.txt : Loading transac [Fri Feb 14 09:28:30 2005] test_of_log.txt : Loading transac [Fri Feb 14 09:28:30 2005] test_of_log.txt : Loading transac [Fri Feb 14 09:28:30 2005] test_of_log.txt : Loading transac [Fri Feb 14 09:28:30 2005] test_of_log.txt : Loading transac [Fri Feb 14 09:28:30 2005] test_of_log.txt : Loading transac [Fri Feb 14 09:28:30 2005] test_of_log.txt : Loading transac [Fri Feb 14 09:28:30 2005] test_of_log.txt : Loading transac ....

I just can't figure it out, shouldn't I get seconds apart on each line? Any help?
Thanks a lot!

In reply to 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.