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

Re: shuffle array



Emanuel Berg wrote on Sun, Dec 01, 2019 at 22:22:27 +0100:
> How do I send the array as a name/pointer argument, i.e. not just the value?

To read an array by name:

f() {
  local array_name=$1
  print -rl -- "${(@P)array_name}"
}
typeset -a foo=(bar baz)
f foo

To write an array by name:

f() { set -A "$1" bar baz }
typeset -a foo
f foo

> Or how can I return the new array and set the old one's value to that?

f() { reply=( bar baz ) }
typeset -a foo 
f
foo=( "${reply[@]}" )

> # from SC on gmane.comp.shells.zsh.user

gmane.comp.shells.zsh.user and zsh-users@xxxxxxx are the same thing. ☺



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