Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a matter of contexts. In Perl, the data type of a value is only part of what evaluates to; the other half is the context that value is used in.</p> <p>As you may know, there are three built-in data types: scalars, arrays, and hashes. There is also some degree of implicit casting that can be done between these data types.</p> <p>There are also two major contexts: list and scalar. Arrays and hashes both work without casting in list context; scalar values work without change in scalar contexts.</p> <p>The behavior of an operator can depend on the context it is run in. If an operator requires a particular context, and Perl is able to implicitly cast the value into something matching that context, it will. In the case of arrays and associative arrays being cast to integers, what you get is the ''cardinality'' of the array, the number of elements it contains.</p> <p>In your example above, <code>@$a</code> evaluates to data typed as an array. The other half of that story, though, is the context in which the operator <code>.</code> runs in. Reading <a href="http://perldoc.perl.org/perlop.html" rel="nofollow noreferrer">perldoc perlop</a>, it says the following: </p> <blockquote> <p>Binary <code>.</code> concatenates two strings.</p> </blockquote> <p>Well, strings are scalar values, and so we need to cast the array <code>@$a</code> to be valid in a scalar context, and in doing so get the back the cardinality of the array. <code>@$a</code> contains 3 things, so this evaluates to the scalar value <code>3</code>, which is then turned into a string so the <code>.</code> operator can work its magic.</p> <p>Hope this makes some sense.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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