Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
May I say, in all respect and courtesy and politeness, m'Lady, perhaps it is that you are “thinking too deeply into it.” Many object-oriented language implementations impose many strictures upon how the language must work; upon how things must be done. Perl does not. (And there are sound engineering reasons for it, which perhaps do not immediately meet the eye.) Therefore, if you are, perhaps unconsciously, trying to carry-over the concepts taken from those languages into this one, you’re going to wind up mightily confused for a while. package is a declaration. It simply notifies Perl about a name that is to be associated with all of the code that follows it, superseding any previous package-name or Perl’s default. The significant thing here is that, when you refer to “a Perl object,” that object is always a package. The subroutines in that package are the object’s methods; new is different as previously noted. But the concept of packages, and the concept of objects, are only loosely related! Start with perldoc perltoot and read that well-written documentation page very slowly and carefully. Especially when it talks about new, which it does several times. Consider, again very slowly and carefully, just what the bless function is actually doing, and why. Of what we mean when we say that something is “a blessed reference,” and, if you like, exactly how the Perl language system represents that notion. (It is literally a bit.) Many object-oriented languages, as I said, are “object-oriented right down to the freckles on their skin.” They simply can’t be approached in any other way. And yet, here is Perl, and it implements the same concepts using just a small handful of concepts, artfully arranged, and never once does it say to you, “this is the Right Way ... you must do it This Way.” Perl-heads are constantly saying, TMTOWTDI = There’s More Than One Way To Do It, and it takes a long time to grok the sheer genius(!) of what they are talking about. You find yourself (or at least, I certainly did...) grasping around, saying, “where’s the rest of it?!” But, then, you start to realize why this community uses the term, Monks. In reply to Re: Why won't a hash in a hash work as a hash reference to create an object?
by sundialsvc4
|
|