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

Re: easy calling of associative array?



These should be robust for Zyx's failure cases (and throw errors in some
other strange cases where they should).  In older zsh where the (b) flag
is not present, (q) will work in MOST cases.

  echo_v () {
    [[ -n $1 ]] && (( ${(P)+1} )) &&
    print -R "${(P)${:-${1}[${(b)2}]}}"
  }

  get_v () {
    [[ -n $1 && $3 != *=* ]] && (( ${(P)+1} )) &&
    typeset -g "${3:-REPLY}=${(P)${:-${1}[${(b)2}]}}"
  }

  set_v () {
    [[ -n $1 ]] && (( ${(P)+1} )) &&
    typeset -g "${1}[${(b)2}]=$3"
  }

  test_v () {
    [[ -n $1 ]] && (( ${(P)+1} )) &&
    [[ ${(P)${:-${1}[${(b)2}]}} = $3 ]]
  }



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