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

Re: Backticks and other tricks



On Mar 28, 11:00am, Sven Wischnowsky wrote:
} 
} Mario Lang wrote:
} 
} > Can anyone cast some light on the following questions
} > regarding the code below:
} > 1. Why does ${(P)...[...]} not work with subscripts of the
} > array? (in fucntion argsargs).
} 
} `array', that's the point.  The ${(P)1} yields an array (a *normal*
} array, not an associative array).

That's not directly the problem ... directly, the problem is that
${(P)1[$i]} first computes ${1[$i]} and then applies (P) to it.

If you get around THAT problem by using ${${(P)1}[$i]}, THEN you get
the problem Sven describes.

Given the relative precedence of flags and subscripts, there's no simple
workaround for this.  We're just going to have to implement ksh namerefs
(not for 4.0.1).

} Currently I don't see a solution other than just not using an
} associative array at all

One can always be creative:

    ${(kP)1}				gives an array of keys, so
    ${${(kP)1}[(i)$i]}			gives the index of the key;
    ${(vP)1}				gives an array of values, so
    ${${(vP)1}[${${(kP)1}[(i)$i]}]}	is the answer.


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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