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

Re: A way to untie -T vars?



On Sat, Jan 21, 2023 at 7:53 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> Speaking of unorthodoxy ...
>
> untie () {
>   emulate -L zsh
>   case ${(tP)1} in
>   (scalar-tied)
>     local scalar=${(P)1}
>     unset $1
>     typeset -g $1=$scalar
>     ;;
>   (array-tied)
>     local array=( ${(P)1} )
>     unset $1
>     # Need eval here for array assignment, as
>     # reserved word doesn't work with $1=(...)
>     eval "typeset -ga $1=( \$array )"
>     ;;
>   (*) ;;
>   esac
> }

Bravo.

`untie scalar` and `untie array` won't work due to name clashes but
this seems easily fixable.

Roman.




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