SPUG: Scope question

Colin Meyer cmeyer at helvella.org
Wed Jun 12 01:54:59 CDT 2002

I said:
> The ::'s aren't meaningful, except to the author of the code (i.e. there's
> not any explicit inheritence between namespaces).
I meant *implicit*.  There's no implicit inheritence between similarly
named namespaces.  All inheritence and aliasing between namespaces is
very explicit with mechanisms like the @ISA array and the Exporter

A reference for further reading: perldoc perlsub
- which 'perldoc -f package' or 'perldoc -f my' lead you to. Scoping in
Perl is discussed throughout the document.

I am in full agreement with Jason's comment about passing parameters
around explicitly. In fact, I read a corny quote from _Code Complete_ at
last month's SPUG meeting to that effect, about parameters being a kiss
on the lips between routines (who's goal is strong cohesion via loose
coupling - or something like that ;-). That is, it gives me a headache
to search around for the meaning of a global variable, when I find it
randomly accessed from deep within some routine of some module. 

However, there are perfecty valid uses for global variables. In a module
that is used for manipulating data in a relational database, how tired
do you get of passing around the database handle into each routine, or
accessing it from buried within your object. Just put it in a global,
document that to be your API, and use it when needed.  Another fine use
of a global is to hold application configuration data.

Have fun,

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org

More information about the spug-list mailing list