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

Re: arrays as arguments to functions



On Mon, 19 Dec 2011 18:58:12 +0100
<meino.cramer@xxxxxx> wrote:
> is it possible to pass an array as an argument to a function and
> if yes: How can I acchieve this?

It's not very comfortable: you just have to pass it by name and refer to
the variable by dereferencing the passed parameter.

% deref() { print ${(P)1}; print ${(P)1[-1]}; }
% array=(there once was a hacker named dave)
% deref array
there once was a hacker named dave
dave

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog



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