|Problems? Is your data what you think it is?|
Subroutines with the same name, in different packagesby mboudreau (Novice)
|on Feb 05, 2010 at 17:48 UTC||Need Help??|
mboudreau has asked for the
wisdom of the Perl Monks concerning the following question:
I can't find this situation discussed in "Programming Perl" (the camel book), "Perl Cookbook" (Christiansen & Torkington), or "Object Oriented Perl" (Conway), but I'm afraid it's a basic OO question with an obvious answer I've just missed. I throw myself on the mercy of the Monks.
I have two packages, "NLMWriter" and "ManifestWriter", that each have subroutines with common names: "new" (a constructor) and "writeInstance" (writes out an XML fragment using data from the newly constructed object).
I assume lots of packages use "new" as the name of their constructor.
When I try to use both packages in a script, I get the "subroutine redefined" error when the second package is loaded. It seems to me that this should be possible, and I should simply have to call each subroutine with the correct package name to avoid confusion, e.g.,
What am I missing?
Package 2 looks nearly the same, with different code in the "new" and "writeInstance" subroutines.
My test script: