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

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



On Mar 9,  6:53am, Han Pingtian wrote:
}
} Looks like this is also the case for (i):
} 
} localhost% foo=abcdefgh
} localhost% print $foo[(r)ab,(i)fg]
} abcdefg
} localhost%
} 
} Though 
} 
} localhost% print $foo[(i)fg]
} 6
} localhost%
} 
} But according to the new contents of manual, this is the same case as
} "(r)fg".

You can't use (i) in ranges.  $s[(i)ab,(i)fg] is an "invalid subscript";
the end of the range is not treated the same as the start.

So although $s[(r)fg] is the same as $s[$s[(i)fg]], $s[(r)ab,(r)fg] is
not the same as $s[$s[(i)ab],$s[(i)fg]].

The foregoing of course all applies only to indexes on scalars; for an
index on an array, the pattern match and resulting index values apply
to entire array elements, so there are no substrings to extract.



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