If I have a data member say “dt” in a perl class (Myclass). I have created two objects of the class say “obj1” and “obj2”. I set “dt” using obj1 as “2”. If I access “dt” through “obj2”, I should get the value of “dt” as 2.
use Myclass;
my $obj1 = new Myclass;
my $obj2 = new Myclass;
$obj1->{dt} = 2;
print $obj2->{dt}; // This should print "2"
How to implement the class to achieve this??
Use the
ourkeyword, which will have package scope:And then: