As far as I know, the static variable aspect that you get with languages like C/C++
is not in ksh93.

I solve the problem using namespace management via a single
compound "master" variable in each library.
If my lib file is abclib, I define a compound var .abclib=()
at the top of the lib file, e.g.

# $Id$
#
.abclib=(
    Rcs=(
        Revision='$Revision$'
        Revision=${.edis.Rcs.Revision#\$Revision: }
        Revision=${.edis.Rcs.Revision% \$}
        File='$RCSfile$'
        File=${.edis.Rcs.File#\$RCSfile: }
        File=${.edis.Rcs.File%,v \$}
    )
    default=(
        Constant1='foo'
        Constant2='bar'
    )
    # and so on...
)

It's still boils down to namespace mgmt, but using a compound varname with
a leading '.' to build a structure has been a very handy technique for me.
It pretty much eliminates name collisions and makes it very easy
to troubleshoot. You can dump the entire structure simply with
  print ".abclib=${.abclib}"

I define some elements with null values and document them,
and then give them real values later.

Cheers,
  Mario


On 10/12/2010 4:40 PM, Kyle McDonald wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all,

Recently I've found myself creating libraries of shell functions. Many
time there are variables that I'd like to keep private to the library.
They either need to be shared between functions in the library or
possibly need to retain values between calls to the same function.

I've managed this so far by just managing the variable namespace, but
I'm curious if there isn't anything better out there?

One thing I had thought of was 'typeset'. Currently it can only be
used in a function to define a variable that is local to that
function. But What if 'typeset' could be used outside a function to
define variables whose scope is only that file?

Has this been discussed before? Are there issues with this?

Or have I lost my mind and I should be doing something totally different?

   -Kyle

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (MingW32)

iQEcBAEBAgAGBQJMtMfHAAoJEEADRM+bKN5wJWYH/j4BlDvTMqYt/LrEUKd/B+YW
RCf1SwFv/+DQNOm+id1ZPXMtw3OEs0o0wGYPA6lVM254bSUj+Jb3OYC0mv+mIN4g
eXf+LMuuEWx/AuyBi1f4x35rl14+bA61BHDQb8zF1V4RUqZClJmk/6NIt4gzIfNV
UuWl5rGmmb+0vfE722fjIAcYj9m7Q0veYThbYUzG7m9SjeIGiI6OSpqeGKWK1TiE
NkS2fP2Qnvj5P/7RgGsqlbUmzVvdc77P+q6YQGQJz9S0Xw2bpwuBaxVgfTdXVs5v
dMZy2pBLWTTkwCoVkSyNxV4iAGe9dZqNPXR+PwVuBORphy7A7I98gh0JWkt2qDU=
=Rl5R
-----END PGP SIGNATURE-----

_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to