JupiterHost.Net wrote:
Hello list,

I saw this recently on here but can't find the thread and since I'm not sure what the technique is called (tie variable to function?) I'm not sure where to look on perldoc :)

What is it called/How do you go about doing it when you have a var that each time is used (IE printed or in calculation) has the current value of a function?

perldoc perltie perldoc Tie::Scalar


package Tie::Time;

use strict;
use warnings;

require Tie::Scalar;
our @ISA = ( 'Tie::StdScalar' );


use Carp;

sub STORE { croak "Can't change time.\n" }

sub FETCH { return time() }


package main;

use strict;
use warnings;

tie( my $time, 'Tie::Time' );

print "$time\n";
sleep( 5 );
print "$time\n";

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to