"Brent Dax" <[EMAIL PROTECTED]> writes: > Piers Cawley: > # In the following code fragment, what context is foo() in? > # > # @ary[0] = foo() > > The short answer is scalar context. The long answer is below. Note > that the long answer is only the way I think of it. You may think > differently. > > I like to think of it as 'one context'. 'Scalar' and 'list' no longer > describe the whole situation. The way I see it, there are three types > of context: > -void context (which could just be 0 context) > -N context > -infinite context (which could just be Inf context) > > Ihe meaning of each of those should be obvious. In that case, 'scalar' > context is really 'one' context. However, we can still call it scalar > context if it makes you feel better. :^) (Yes, those are just my > opinions. They do not necessarily reflect Larry's, Damian's or the guy > in the padded cell next to mine's.)
Okay. Here's the examples I threw at Dan. @ary[0] = foo() # scalar @ary[1,2] = foo() # list context @bar = 1; @ary[@bar] = foo() # ? probably list or maybe scalar... @bar = (1,2); @ary[@bar] = foo() # list? @bar is constant = 1; @ary[@bar] = foo() # We know at compile time there's only one thing in # @bar. Does that mean foo() is in a scalar context # now? sub a_scalar { 1 }; sub an_array { my @a = (1,2) } sub context { wantarray ? (1,2) : 1 } @ary[a_scalar()] = foo() # ??? @ary[an_array()] = foo() # ??? At around this point, Dan was heard to say 'Mommy, make the bad man go away!' @ary[context()] = foo() # ??? Oh yes, and what context is &context called in? And, just for laughs: $ref = [1,2]; @ary[$ref] = foo(); # probably a syntax error -- Piers "It is a truth universally acknowledged that a language in possession of a rich syntax must be in need of a rewrite." -- Jane Austen?