Anonymonk, now explain why you think the value of that scalar should change over time. Do you assign the value of localtime() many times? Do you think that by calling your subroutine, it somehow magically knows to update the value stored in $localtime? I don't understand your difficulty.
| [reply] [d/l] [select] |
Just explain, if localtime has a different time to a fraction of a second, how come when the program interacts in a loop it wouldn't give a different time for a new line, since localtime is getting called again by this new interaction inside of the loop. That's what I can't understand.
| [reply] |
...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
| [reply] [d/l] [select] |
Yes. We all noticed that. But how many times does that piece of code get executed? It looks as tho' it's only called once, so the value of $localtime is set once but never changed.
--
< http://dave.org.uk>
"The first rule of Perl club is you do not talk about
Perl club." -- Chip Salzenberg
| [reply] |
How could I have it changing in every line inside of the loop?
| [reply] |
How could I have it changing in every line inside of the loop?
By using any of the suggestions that you have already been given here.
If they don't work, then the problem is somewhere in the code that you haven't shown us. I suggest that you strip your problem down to complete runnable program with about ten or twnety lines of code. Then we'll be able ot give you better help.
--
< http://dave.org.uk>
"The first rule of Perl club is you do not talk about
Perl club." -- Chip Salzenberg
| [reply] |