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

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



On Mar 5,  4:30pm, Han Pingtian wrote:
} Subject: wrong array range with (r) flag on scalar?
}
} Hi,
} 
} Looks like this is wrong:
} 
} localhost% a='hello world'
} localhost% print $a[(r)h?]
} h
} localhost% print $a[(r)h?,(r)w?]
} hello wo
} localhost%
} 
} In the range, the end should be "w" and the result should be "hello w"?

The range goes from the start of the left pattern to the end of the
shortest match for the second pattern.  This is the only thing that
makes sense if the range is going to be "inclusive" of the end of the
pattern match.  With (R), it's the end of the longest match for the
second pattern.

Would you expect

torch% print $a[(r)h?,(r)wo] 
hello wo

to stop at the "w"?  

The doc could certainly be more clear about this.



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