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

Re: is a key of pointed key set ? (where is the + )



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Monday 06 November 2006 13:13, Marc Chantreux wrote:
> le 06/11/2006,
>
> Andrey Borzenkov nous écrivait :
> > > pnt=h
> > > typeset -A h
> > > h=( k1 value )
> > >
> > > so :
> > >
> > > echo ${${(P)pnt}[k1]}
> > > prints value
> > >
> > > but how to know if the key itself is set ?
> >
> > {pts/0}% typeset -A h
> > {pts/0}% h=(k v)
> > {pts/0}% print -- ${(k)h[k]+set}
> > set
> > {pts/0}% print -- ${(k)h[k1]-unset}
> > unset
>
> well .. (( $+h[k] )) does the same. You missed a part of the problem :
> my associative array is "Pointed" (P).
>

Somewhat kludgy but

{pts/0}% typeset -A h
{pts/0}% h=(k1 v1 k2 v2)
{pts/0}% p=h
{pts/0}% print -- ${${(Pk)p}[(r)k3]-unset}
unset
{pts/0}% print -- ${${(Pk)p}[(r)k2]+set}
set


> so we can imagine :
>
> [[ -n ${(k)${(P)pnt}[k1]} ]] && print "${pnt}[k1] is set"
>
> but it doesn't work.
>

I believe this was discussed recently. Parameter type is not propagated from 
nested substitutions, so this is not going to work. Outside of innermost 
${...} you just get list of values. Even without (P):

{pts/0}% print -- ${(k)${h}}
v1 v2
{pts/0}% print -- ${(k)${(kv)h}}
k1 v1 k2 v2

- -andrey
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQFFTxhwR6LMutpd94wRApfCAJ9Q3/5QdxdTGPmBQIm3cn9YqItL3ACfeZpZ
70APA+FBiocoEIHj/NY7Mpk=
=Y63j
-----END PGP SIGNATURE-----



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