Hi All,

As learning perl again, I came upon TIE.
My idea on creating a class, monitoring access to temperture (by
saving the modified date).
Q: can i define other subroutines to class, uses tie ?


Here is what I wrote:
=================

package Temperture;
sub TIESCALAR
{
    my ($pkg, $temp) = @_;
        my $cdate = time();
        
        my $ref_temp = { temp => undef, cdate => $cdate, mdate => $cdate };
        bless $ref_temp, "Temperture";
        return $ref_temp;
}
sub FETCH
{
   my ($self) = @_;
   return $self->{temp};
}
sub STORE
{
   my ($self, $new_temp) = @_;
   $self->{temp} = $new_temp;
   $self->{mdate} = time();
   return $self;
}
sub get_mdate
{
    my ($self) = @_;
    return $self->{mdate};
}

package main;
tie my $t, "Temperture";
$t = 10;
print $t->get_mdate();

-- 
===================
----     Chanan Berler    ----
===================
_______________________________________________
Perl mailing list
Perl@perl.org.il
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to