in reply to Re^8: If you believe in Lists in Scalar Context, Clap your Hands
in thread If you believe in Lists in Scalar Context, Clap your Hands
If you can't have a list in a scalar context, how can you have the assignment of a list in scalar context?Because any operator can be scalar context; it's the context that determines its context, not their operands. Here are a few examples of operators in scalar context:
Here are some examples of operators in list context:scalar ($a + $b); # Addition scalar (($a) x $b); # Repetition scalar ($a =~ $b); # Matching scalar ($a .. $b); # Range/FlipFlop scalar ($a = $b); # Scalar assignment scalar (($a) = ($b)); # List assignment
One should realise that 'scalar assignment' and 'list assignment' are two different operators (sassign and aassign in pp_hot.c). It's the LHS of the '=' that determines which operator it is (this is unlike the '..' operator where it's the context that determines whether it's the range or the flipflop operator). The side-effects (that is, the actual assignment) of both sassign and aassign are independent of the context. However, the return value of the aassign operator is context dependent. In scalar context, it returns the number of elements appearing on its RHS.say ($a + $b); # Addition say (($a) x $b); # Repetition say ($a =~ $b); # Matching say ($a .. $b); # Range/Flipflop say ($a = $b); # Scalar assignment say (($a) = ($b)); # List assignment
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^10: If you believe in Lists in Scalar Context, Clap your Hands
by ikegami (Patriarch) on Oct 26, 2008 at 10:07 UTC | |
Re^10: If you believe in Lists in Scalar Context, Clap your Hands
by Anonymous Monk on Oct 29, 2008 at 00:40 UTC | |
by JavaFan (Canon) on Oct 29, 2008 at 11:29 UTC |
In Section
Meditations