Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: proxy name for array
This works. Double indirection, but she runs.
function called ()
{
# Am I tempting the wrath of the Gods? :
temp=( ${(P)${(P)1}[pages]} ) # Temporary array will be used to
hold content of 'Pages' (or whatever else).
temp[2]=50 # Set some test values.
temp[3]=100
temp[4]=150
echo 10: $temp # How are we doing?
echo 11: $temp[3] # So far so good.
set -A "${${(P)1}[pages]}" $temp # The hard part: write 'temp'
back to 'Pages' via the named input array.
}
typeset -A main=() # The main structure. Contains a dozen elements
but we only need one here ...
main[pages]=Pages # The name of the pages array.
Pages=( 1 ) # Initialize. This is going to end up as an
array of numbers.
# Now we jump into the function that will modify 'Pages' -- or whatever
other name is held in '[pages]' of whatever structure name is passed.
called main # Push the button. Don't look at the flash.
echo 13: ${(P)main[pages]} # It's Alive! It's alive, it's alive,
it's alive!
echo 14: ${(P)main[pages][3]} # Now I know what it's like to be Mark!
;-))
echo "Who said zsh doesn't have structures? She does, they're just a
bit tricky to build."
----------------------------------------------
... subject to improvement of course. Or can 'temp' be avoided by
direct access to 'Pages' but via similar indirection? Probably too
complicated.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author