Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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??


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:
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.


Comment on Re^9: If you believe in Lists in Scalar Context, Clap your Hands
Select or Download Code
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?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://719579]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2014-07-29 18:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (226 votes), past polls