Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Do the parentheses around $x do anything?
It's one of the few cases where parenthesis actually create a list.
It seems to me that the rhs will always be a scalar,
Actually, in this case, it isn't. The context of the RHS of an assignment is determined by the LHS. In fact, assignment in list context is a different operator from assignment in scalar context - although both of them are represented by the same symbol. The important thing is context. The context of an expression is always determined by the context (duh!), and never by the expression itself. If the LHS of an assignment is a list, the RHS is in list context, regardless of how the RHS looks like.
and these are equivalent
They are equivalent in the sense they print the same thing. Do you consider:
my $x = 3 - 1; say $x;
and
my $y = length "ab"; say $y;
to be equivalent?

In your example, in the first case, $x gets the value of the scalar expression on the RHS of the assignment. In the second case, $y is assigned the value of the first element of the list on the RHS of the assignment. There's a difference. Whether you find the difference significant enough to call it not equivalent, or small enough to call it equivalent, I leave up to you. As long as you know what the difference is, it doesn't matter how you label it.


In reply to Re: list context by JavaFan
in thread list context by 7stud

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 23:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found