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

easy calling of associative array?




test ()
{
    eval "baz=\$${1}[key1]"
    echo $baz
eval "foo=\$${1}[key2]"
    echo $foo
...
}

If I want to pass the name of an associative array to a function via "$1" and then work with it's keys, the above succeeds but it's sure laborious. Is there some way to do the eval just once? So that I can end up doing:

if [ "xyz[key1]" = '1' ]; then ...

... as I experiment, there seems to be no way of replacing 'xyz' with any expression that will do the job without needing eval's help every time, but I'll bet there's a way.



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