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

Re: wrong array range with (r) flag on scalar?



# schaefer@xxxxxxxxxxxxxxxx / 2015-03-05 08:44:08 -0800:
> Would you expect
> 
> torch% print $a[(r)h?,(r)wo] 
> hello wo
> 
> to stop at the "w"?  

yes, but only *after* reading this carefully:

  r  Reverse subscripting: if this flag is given, the exp is taken as
     a  pattern  and  the result is the first matching array element,
     substring or word (if the parameter is an  array,  if  it  is  a
     scalar,  or if it is a scalar and the `w' flag is given, respec-
     tively).  The subscript used is the number of the matching  ele-
     ment,  so  that  pairs of subscripts such as `$foo[(r)??,3]' and
     `$foo[(r)??,(r)f*]' are possible if  the  parameter  is  not  an
     associative  array.

note: "The subscript used is the number of the matching  element".

i would definitely expect a (0-based indexing, pseudocode)
`substr foobar bar` to be 3, not 5.

> The doc could certainly be more clear about this.

oh yeah. :)

-- 
roman



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