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

Re: creating associative arrays



On Tue, Dec 11, 2001 at 07:45:22PM +0100, Akos Szalkai wrote:
> I am trying to fill an associative array from a file.  If the name of
> the file is fixed, e.g. array.txt then the following works:
> 
> : ${(AA)dict::=$(<array.txt)}
> 
> However, if the filename is given in a parameter then the command:
> : ${(AA)dict::=$(<${filename})}
> gives the error
> zsh: bad set of key/value pairs for associative array.

Sorry for having a conversation with myself here, but I realized that it
has to do with splitting.  If in the second case I use
: ${(AA)=dict::=$(<${filename})}
or anything similar, like
: ${(AA)dict::=${(z)$(<${filename})}}
it all works.  Thinking about it (hopefully with a clearer head than last
night) the error message seemed to be the correct behavior.

However, the question remains: why did the first case (with the filename
given directly instead of by a parameter) work then?

Akos

-- 
Akos Szalkai <szalkai@xxxxx>
IT Consultant
2F 2000 Szamitastechnikai es Szolgaltato Kft.
Tel: (+36-1)-4887700  Fax: (+36-1)-4887709  WWW: http://www.2f.hu/



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