Although it gets a bit hairy, one can explain that behavior by saying that my $a = (10,20,30); is merely an application of the comma operator in scalar context, whereas the rhs of my $a = (10,20,30)[0..2] is really a list, and so the behavior of taking the last value has to be explicitly defined. The distinction is important because I believe that my $a = (1,2,foo) would call foo in scalar context, but my $a = (1,2,foo)[0..2] would call it in list context.
The preceding paragraph will be moot someday because according to Apocalypse 3, there will be no scalar comma operator in Perl 6 - it will always be a list, and a list in scalar context will return an array reference
-
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.
|