Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: problem with RANDOM and arrays



2010-01-11 20:58:46 +0000, Stephane Chazelas:
> 2010-01-11 20:13:12 +0000, Stephane Chazelas:
> [...]
> > Similar problem:
> > 
> > $ x=0; ((a[++x]++)); echo $x
> > 2
> > 
> > All the +=, -=, *=... operators are also affected.
> [...]
> 
> Strange, their must be something in my .zshrc that affects the
> behavior as I get:
> 
> $ zsh -c 'x=0; ((a[++x]++)); echo $x'
> 1
[...]

Well no, actually it's the fact that "a" is previously unset
that affects the behavior:

~$ unset a
~$ x=0; ((a[++x]++)); echo $x
1
~$ unset a
~$ a[1]=0
~$ a[2]=0
~$ x=0; ((a[++x]++)); echo $x
2
~$ unset a
~$ a[3]=0
~$ x=0; ((a[++x]++)); echo $x
2


So the behavior is slighly worse than in bash or ksh93 (which
consistently give 2 above).

-- 
Stephane



Messages sorted by: Reverse Date, Date, Thread, Author