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