my $time =... # do magic to make $time always return time()
print "$time\n"; sleep 3; print "$time\n";
would output:
1101740477 1101740480
Thanks everyone that replied, that is exactly what I was looking for!
I beleive I have it now :)
I wonder now, is doing this very resource intensive:
When I benchmark it:
print "Hi " . time(); sleep(3); print "Hi" . time();
versus
package Local::Tie::Time;
require Tie::Scalar;
our @ISA = ( 'Tie::StdScalar' );
use Carp;
sub STORE { croak "Can't change time.\n" }
sub FETCH { return time() }
package main;
tie( my $time, 'Local::Tie::Time' ); print "Hi $time"; sleep(3); print "Hi $time";
the tie ranges from 2% slower to 20% slower must be sytem usage causeing the flux eh?
Benchmark: timing 2000000 iterations of func, tie...
func: 1.04812 wallclock secs ( 0.87 usr + 0.00 sys = 0.87 CPU) @ 2298850.57/s (n=2000000)
tie: 1.40371 wallclock secs ( 0.93 usr + 0.00 sys = 0.93 CPU) @ 2150537.63/s (n=2000000)
Rate tie func
tie 2150538/s -- -6%
func 2298851/s 7% --
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
