Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The answer can be found by consulting perldoc's <a href="http://perldoc.perl.org/perlop.html#Range-Operators" rel="nofollow">perlop</a> page:</p> <blockquote> <p>Binary ".." is the range operator, which is really two different operators depending on the context. In list context, it returns a list of values counting (up by ones) from the left value to the right value... </p> </blockquote> <p>This is the familiar usage, which is invoked by <code>print "a" .. "c";</code> because arguments to functions are evaluated in list context. (If they were evaluated in scalar context, then <code>print @list</code> would print the size of <code>@list</code>, which is almost definitely not what people usually want.)</p> <blockquote> <p><strong>In scalar context, ".." returns a boolean value.</strong> The operator is bistable, like a flip-flop, and emulates the line-range (comma) operator of sed, awk, and various editors. Each ".." operator maintains its own boolean state, even across calls to a subroutine that contains it. <strong>It is false as long as its left operand is false. Once the left operand is true, the range operator stays true until the right operand is true, AFTER which the range operator becomes false again.</strong> It doesn't become false till the next time the range operator is evaluated. It can test the right operand and become false on the same evaluation it became true (as in awk), but it still returns true once. If you don't want it to test the right operand until the next evaluation, as in sed, just use three dots ("...") instead of two. In all other regards, "..." behaves just like ".." does.</p> </blockquote> <p>It goes into further detail, but the bolded sections are the important parts to understanding how the operator works. Scalar context is forced by <code>$a =</code>, i.e. assignment to a scalar lvalue. If you did <code>@a =</code>, it would print what you expect.</p> <p>Note that <code>"a" .. "b"</code> doesn't produce the string <code>"abc"</code>, it produces the list <code>("a", "b", "c")</code>. You will get similar results if you used the list (though the value printed when the list is forced into scalar context will differ).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload