[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
YAQAGV (Yet Another Question About Global Variables)
From: |
Steven W. Orr |
Subject: |
YAQAGV (Yet Another Question About Global Variables) |
Date: |
Tue, 23 Aug 2011 09:42:21 -0400 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.20) Gecko/20110804 Thunderbird/3.1.12 |
I made a decision to implement the require module written by Noah Friedman
that comes in the examples part of the bash distro. This is the trick for
implementing the provide / require functionality of features.
I love it. It works great. I just ran into one little snag. Not a show
stopper, but I'm wondering if there's a better way to deal with it.
Some of the modules I have are designated as library modules, and so are used
as args to require. Since require is a function, any variables that are
declared in a required module which declare global variables using typeset
then become local variables to the require function. Then after the modules
are loaded, the variables that used to be global are gone.
I went through the library modules and removed the typeset commands from all
of the global variables and that seems to fix it. What got lost however was
the functional part of the typset commands. For example, a variable was
declared as
typeset -a foo=( abc def ghi )
and now it has to be changed to
foo=( abc def ghi )
No big loss. But I also had some things declared as constants or integers (or
both).
typeset -i x1=44
typeset -ir x2=55
I'm not 100% sure that that won't break something, but for now I'm just glad
that they didn't go out of scope.
Is there a trick to allow declarations like I used to do in a module and
preserve their characteristics if they are sourced in from inside a function?
If there's an answer, I'll get it here.
TIA
--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
- YAQAGV (Yet Another Question About Global Variables),
Steven W. Orr <=