[oak perl] Lexical vs. Package variables

Jon Seidel, CMC jseidel at edpci.com
Mon Feb 7 18:14:59 PST 2005


>> But now I'm grappling with the *basic* idea of scoping:
>> that you're cordoning off a part of your script with a scoped
>> value so that a variable with an identical name elsewhere
>> in the code is unaffected.

This is absolutely the point -- you've got it. Now just generalize your
thinking about programs to include *large* programs... programs that have
many different subroutines to get the job done. What if you wanted a
simple counter (e.g., $i) to count things during a loop. If you couldn't
localize them, you'd have to use $i1 for the first subroutine, $i2 for the
second subroutine, and so on. With even a moderate-sized system, this can
get to be a real pain and the source of obtuse bugs. I know; a system that
I programmed in many years ago had exactly that problem...

>>
>> This actually seems pointless, if I'm foolish enough to
>> believe that a script is always a linear affair, like driving
>> a car past scenery.

Don't think of a *coding* script as a linear affair... think of the
*execution* of the script as linear. If your code is executing in the main
routine, then calls subroutine-1, which calls subroutine-2, then that's
the "linearity" that is relevant... and which is what makes localized
variables so valuable.

Hope this helps...jon




-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

      Connecting Business and Technology

Jon Seidel, CMC                   +1-510-530-6314
EDP Consulting, Inc.                www.edpci.com

CMC (Certified Management Consultant) is a certification mark awarded by
the Institute of Management Consultants USA and represents evidence of the
highest standards of consulting and adherence to the ethical canons of the
profession. Less than 1% of all consultants have achieved this level of
performance. See www.imcusa.org/hireacmc.acgi.



More information about the Oakland mailing list