Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Problem with associative arrays
- X-seq: zsh-workers 4773
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- To: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>, zsh-workers@xxxxxxxxxxxxxxx
- Subject: Re: Problem with associative arrays
- Date: Mon, 14 Dec 1998 07:47:47 -0800
- In-reply-to: <199812141055.LAA07255@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- References: <199812141055.LAA07255@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
On Dec 14, 11:55am, Sven Wischnowsky wrote:
} Subject: Problem with associative arrays
}
} Subscripts for associative arrays are matheval()ed
No, they are not. The code in params.c looks like
if (PM_TYPE(v->pm->flags) == PM_HASHED) {
...
} else
if (!(r = mathevalarg(s, &s)) || (isset(KSHARRAYS) && r >= 0))
...
} which makes some problems:
}
} % set -A a
You have to use `typeset -A a` to get an associative array. `set -A a`
creates an ordinary array. I realize this is confusing, which is why I
originally used a different option letter for typeset, but compatibility
with ksh requires -A.
} % a[foo]=bar
} % echo $a[baz]
} bar
}
} There is no variable baz, so evaluating it yields zero and since
} numeric subscripts on associative arrays work, this yields the `first'
} value.
This is all accurate, for ordinary arrays.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Messages sorted by:
Reverse Date,
Date,
Thread,
Author