go ahead... be a heretic PerlMonks

### Re^9: If you believe in Lists in Scalar Context, Clap your Hands

by JavaFan (Canon)
 on Oct 25, 2008 at 22:52 UTC ( #719579=note: print w/replies, xml ) Need Help??

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:
```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
Here are some examples of operators in list context:
```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
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.

Replies are listed 'Best First'.
Re^10: If you believe in Lists in Scalar Context, Clap your Hands
by ikegami (Pope) on Oct 26, 2008 at 10:07 UTC

it's the context that determines its context

```Deep recursion on "context" at PerlMonks post 719579
Terminating on signal SIGINT(2)
:)
Re^10: If you believe in Lists in Scalar Context, Clap your Hands
by Anonymous Monk on Oct 29, 2008 at 00:40 UTC
Because any operator can be scalar context, including the list operator.
How does the "list operator" look like?

Create A New User
Node Status?
node history
Node Type: note [id://719579]
help
Chatterbox?
 [choroba]: Snow here. Good morning nonetheless. [Corion]: A good morning to you too, Discipulus! [Discipulus]: ah! buran stroke again?

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2018-03-19 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (236 votes). Check out past polls.

Notices?