ObjectVariableTest.pl to HTML.

index -|- end

Generated: Sun Aug 21 11:11:17 2011 from ObjectVariableTest.pl 2010/09/03 1.5 KB.

#- ObjectVariableTest.pl
#- Copyright (c) 1999 by Dr. Herong Yang, http://www.herongyang.com/
#- from : http://www.herongyang.com/Perl/Object-Variable-and-Class-Variable.html
# 03/09/2010 - Created for viewing, testing, understanding...
package Account;
   $euroRate = 0.85;
sub print {
   my $this = shift;
   my $currency = shift;
   my $balance = $$this{"Balance"};
   $balance *= $euroRate if ($currency eq "EURO");
   print("Printing account...\n");
   print("   Name = ",$$this{"Name"},"\n");
   print("   Type = ",$$this{"Type"},"\n");
   print("   Balance = ",$balance,"\n");
}
sub deposit {
   my $this = shift;
   my $amount = shift;
   $$this{"Balance"} += $amount;
}
sub setEuroRate {
   my $class = shift;
   $euroRate = shift;
}
package main;
   %myAccount = {};
   $myAccount{"Name"} = "Herong Yang";
   $myAccount{"Type"} = "Checking";
   $myAccount{"Balance"} = 100.00;
   $myObj = \%myAccount;
   bless($myObj,Account);

   %hisAccount = {};
   $hisAccount{"Name"} = "Mike Clinton";
   $hisAccount{"Type"} = "Saving";
   $hisAccount{"Balance"} = 999.00;
   $hisObj = \%hisAccount;
   bless($hisObj,Account);

   print("\nTest 1:\n");
   $myObj->print();
   $hisObj->print();

   print("\nTest 2:\n");
   $myObj->deposit(-25.00);
   $hisObj->deposit(99.00);
   $myObj->print();
   $hisObj->print();

   print("\nTest 3:\n");
   $myObj->print("EURO");
   $hisObj->print("EURO");

   print("\nTest 4:\n");
   Account->setEuroRate(0.80);
   $myObj->print("EURO");
   $hisObj->print("EURO");
   exit;

index -|- top

checked by tidy  Valid HTML 4.01 Transitional