jrhdpt02:/root/big# cat a1.pl
unshift(@INC,"/root/big2");
require RegularEmployee;
use Data::Dumper;
$var=RegularEmployee::new(a,b,c,d);
my $xx= Dumper($var);
print $xx;
print "
";
jrhdpt02:/root/big# perl a1.pl
$VAR1 = bless( {
'months_worked' => 0,
'monthly_salary' => 'd',
'position' => 'c',
'name' => 'a',
'age' => 'b'
}, 'RegularEmployee' );
没有bless呢?
jrhdpt02:/root/big# cat RegularEmployee.pm
package RegularEmployee;
sub new {
my ($name,$age,$starting_position,$monthly_salary)=@_;
my $r_employee = {
"name" =>$name,
"age" =>$age,
"position" => $starting_position,
"monthly_salary" => $monthly_salary,
"months_worked" =>0,
};
#bless $r_employee,'RegularEmployee';
return $r_employee; ##返回对象的引用
}
sub promote{
#...
}
1;
jrhdpt02:/root/big# cat a1.pl
unshift(@INC,"/root/big2");
require RegularEmployee;
use Data::Dumper;
$var=RegularEmployee::new(a,b,c,d);
my $xx= Dumper($var);
print $xx;
print "
";
jrhdpt02:/root/big# perl a1.pl
$VAR1 = {
'months_worked' => 0,
'monthly_salary' => 'd',
'position' => 'c',
'name' => 'a',
'age' => 'b'
};