more useful options | |
PerlMonks |
Re: why is a 2-argument bless not working in my situationby Vautrin (Hermit) |
on Mar 31, 2004 at 04:31 UTC ( [id://341197]=note: print w/replies, xml ) | Need Help?? |
All subroutines (or functions or methods or whatever you were taught to call them in CS101) in perl return a value. You can explicitely return a value by using a return statement, or, the last line is returned. For instance, in the function:
You would see an output of 1. Now, you never explicitely returned a value of 1, but because it was the last thing on the line, Perl tried to do what you meant by returning 1. However, Perl is not psychic. So, when you see most constructors ending with:
$self is not modified. An object is created when bless is evaluated. The following would do the same thing:
Consult perldoc bless for more information. So, this:
should read:
Also, note that the first element of @_ is the class name, not the second. So:
Should really be the other way around, i.e.:
And unless you know what you're doing, you shouldn't use anything but a hashref for $self. I think you might want to google for @ISA and read up a little bit on inheritance. Want to support the EFF and FSF by buying cool stuff? Click here.
In Section
Seekers of Perl Wisdom
|
|