Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Associative array index.
- X-seq: zsh-workers 10554
 
- From: Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxxx>
 
- To: zsh-workers@xxxxxxxxxxxxxx (Zsh hackers list)
 
- Subject: Associative array index.
 
- Date: Thu, 06 Apr 2000 18:09:33 +0100
 
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
 
I'm sure we've had this discussion but the behaviour is still inconsistent.
The lexer and the parameter code disagree over the handling of associative
array indices.
% typeset -A foo
% foo=("'" ouch)
% print $foo['
quote> 
but
% print $foo[']'
ouch
Maybe the lexer can be educated, but doing it this way we are always going
to have problems with any expression with `]' in it, especially since no
form of quoting works in the [...].  I'd prefer to do it the way perl does
it, which is if you want quoting you add it yourself.  The current way of
doing it is supposed to be like a double-quoted string, but it isn't, as
this example shows.  I should offer a prize for anyone able to extract
the value of
  foo=("]" ouch)
by direct indexing.  Indirect indexing using a parameter is OK, although
this can get confused, too.
% print ${nonexistent:-"]"}
]
% print $foo[${nonexistent:-"]"}]
zsh: parse error
which shows how thoroughly horrible it is.
-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxxx>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070
Messages sorted by:
Reverse Date,
Date,
Thread,
Author