Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: easy calling of associative array?
On Nov 2, 10:32am, Ray Andrews wrote:
} Subject: Re: easy calling of associative array?
}
} On 11/02/2015 08:28 AM, Bart Schaefer wrote:
} >
} > set_v () {
} > typeset -g "${1}[$2]=$3" # quotes so [ ] isn't globbing
} > }
}
} I've never seen 'typeset' used to refer to anything but a simple
} variable.
In the above,
set_v ary idx val
is going to invoke
typeset -g ary[idx]=val
because $1 $2 $3 are all expanded after parsing and before calling the
typeset command. (Zyx has pointed out the lack of robustness.) Note
that it is not affecting any positional parameters, they're all long
gone (replace by their values) before typeset begins.
} I note that the above does not work without the 'typeset -g' so what
} does that accomplish?
Ordinarly "typeset" inside a function body behaves like "local". The
-g option tells it not to do that, so that the name "ary" is taken to
come from the calling context instead of the current function context.
} BTW, as a point of list etiquette: Responding to most posts I let my
} lines wrap
} but resonding to yours, which seem to alway have fixed line width, I try to
} match that style, but looking at the returned posts from the list, they
} sometimes
} sproing badly. Should I try to keep to your width, or just let lines wrap?
The above is what your text would look like if I didn't run it through
a reformatter. It Used To Be that everyone assumed text should be
folded to be readable on an 80-column display, which, as a guy still
using the email program I wrote myself 20 years ago, I still do. Then
along came HTML format email, and everybody assumed text should never be
wrapped at all (let the reader's UI deal with it). Except there's still
this pesky thing about mailing lists preferring plain text, so we end up
with a hypbrid where text as you write it is folded to be readable at
whatever your display width is set, but then it gets re-folded to 80
when you send it -- except that it also keeps any real newlines you
entered, so if you were actually trying to make it look nice, it ends
up like the above instead.
Exactly what you SHOULD do depends on what you're using to write your
email. In Thunderbird you should probably put literal line breaks only
at the ends of paragraphs, and let it wrap other stuff as it wills.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author