Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: clone an associative array?
- X-seq: zsh-workers 21672
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers <zsh-workers@xxxxxxxxxx>
- Subject: Re: clone an associative array?
- Date: Fri, 19 Aug 2005 15:24:52 +0100
- In-reply-to: <20050819141338.GA5747@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20050819141338.GA5747@xxxxxxxxxxxxxxxxxxxxxxx>
Marc Chantreux wrote:
> hello all,
>
> i don't know what i missed in 'parameters expansions' manual but i'm
> unable to clone an associative array :
>
> % typeset -A homemade
> % homemade=( tm myself c 2005 )
> % echo $homemade[tm]
> myself
>
> % typeset -A counterfeit
> % counterfeit=${homemade}
As it's a sort of array, you need braces. However, you also need
to copy keys as well as values. The syntax is:
typeset -A counterfeit
counterfeit=(${(kv)homemade})
Make sure you don't have the option SH_WORD_SPLIT set. (This is a
classic example of why it's a good idea to get used to doing without it.)
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
**********************************************************************
Messages sorted by:
Reverse Date,
Date,
Thread,
Author