Author: autrijus Date: Tue May 2 10:46:43 2006 New Revision: 9103 Modified: doc/trunk/design/syn/S02.pod
Log: * S02: Clarify that subscripts evaluates under list context at RHS, but scalar context at LHS. Also adds some example code to illustrate various interactions. Modified: doc/trunk/design/syn/S02.pod ============================================================================== --- doc/trunk/design/syn/S02.pod (original) +++ doc/trunk/design/syn/S02.pod Tue May 2 10:46:43 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 10 Aug 2004 - Last Modified: 1 May 2006 + Last Modified: 2 May 2006 Number: 2 - Version: 36 + Version: 37 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -589,10 +589,21 @@ =item * The context in which a subscript is evaluated is no longer controlled -by the sigil either. Subscripts are always evaluated in list context -on the assumption that slicing behavior is desired. If you need to -force inner context to scalar, we now have convenient single-character -context specifiers such as + for numbers and ~ for strings. +by the sigil either. Subscripts are always evaluated in scalar context +when used as a lvalue, and list context when used as a rvalue. + +If you need to force inner context to scalar, we now have convenient +single-character context specifiers such as + for numbers and ~ for strings. +Conversely, put parenthesis around the lvalue expression to force inner +context to list: + + @x[f()] = g(); # scalar context for f() and g() + @x[f()] = @y[g()]; # scalar context for f(), list context for g() + @x[f()] = @y[+g()]; # scalar context for f() and g() + + (@x[f()]) = g(); # list context for f() and g() + (@x[f()]) = @y[g()]; # list context for f() and g() + (@x[f()]) = @y[+g()]; # list context for f(), scalar context for g() =item *