Hi Monks,
I'm from a C++ background, and I'm struggling with some of Perl's library and OO-like features. I understand that Perl doesn't allow full encapsulation of data with in a package. What I don't quite understand is *how* I should go about passing data that I might want to be "private" to a package.
To be more precise, I have a package that will have three basic subroutines:
sub search_simple($) { # do stuff } sub search_normal($) { # do stuff } sub search_extended($) { # do stuff }
The thing is, each of these subs do very similar things, but with different parameters which are set in the subs. I would like to have something like this:
sub process_search($) { # do stuff } sub search_simple($) { # set parameters return process_search($); } sub search_normal($) { # set parameters return process_search($); } sub search_extended($) { # set parameters return process_search($); }
So, the crux of my question is: how do I set the parameters most effectively? Will our create a package-level variable? Or should I just be passing around hash-references so that they're destroyed after the sub is called (assuming the reference-count is 0)? Or am I maybe thinking about this all wrong?
Any suggestions/advice/criticism encouraged! :)
In reply to Package-Level Variables by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |