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

Re: Implement a key-value deserialization or something similar



Sebastian Gniazdowski wrote on Mon, Sep 05, 2016 at 22:47:11 +0200:
> Hello,
> I'm wondering how to best implement a parameter $x, say $7 – I mean a
> last parameter to a parameter-rich function – that would serve as "put
> various key-data things here to stop adding more parameters"? Possible
> call could be: afunction param1 param2 ... "MYDATA=1 OTHERDATA=true"

Like this:

    % local -A reply=(mydata 1 otherdata true) 
    % () { echo ${${(P)7}[otherdata]} } {1..6} reply 
    true

Or you could adopt the Perl convention:

    () {
      local -A args=( "$argv[@]" )
    } mydata 1 otherdata true
  



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