in reply to Timing Files in Directory

That's because localtime() is only called once (during the variable assignment), not every time you print out the variable. If you want the time to be taken in each loop iteration you either need to assign to the variable inside the loop:

foreach my $allfilesfound (@dir_contents) { my $time = localtime(); print "This file=$allfilesfound took $time to open<br>"; }

Or assign it an anonymous subroutine and call that in the loop.

my $time = sub { localtime() }; foreach my $allfilesfound (@dir_contents) { print "This file=$allfilesfound took ".$time->()." to open<br>"; }

BTW, I'm assuming that you do more inside the loop than your example code shows, because this code doesn't actually open the file at all. Also, check out Time::HiRes for more accurate timing.


All dogma is stupid.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.