XP is just a number | |
PerlMonks |
Re: Need help with OO perlby kyle (Abbot) |
on Dec 27, 2008 at 02:37 UTC ( [id://732740]=note: print w/replies, xml ) | Need Help?? |
In test2::new, you say:
That doesn't cause any error, but it doesn't do what you want it to do. It leaves $self->{lib} == 1, which is what print returns at the end of test1::print_name. Later, in test2::get_name, you try to use $self->{lib} as an object instance, but it's still just the number 1. I'd fix this by changing the code in test2::new to:
You could also eliminate a variable this way:
You could also "fix" this by having test1::print_name return $self instead of the value of print
I don't like that solution personally since the return value isn't really related to the method, but having methods return $self whenever possible is common enough.
In Section
Seekers of Perl Wisdom
|
|