Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Comment on


This is one of those times when there is a difference between a list and an array in Perl. It seems hard to produce a concise definition of the difference, but to a first approximation an array is a list with a name (such as @a in your examples). So qw(a b c d e) is a list which you have assigned to @a.

What you have exposed is that in scalar context, a array and list (both containing the same data) have different values. The value, in scalar context, of an array, is the number of elements. The value, in scalar context, of a list, is the last item in that list.

Update. See perlfaq4

In reply to Re: Confused as to why the "casting context" is mis-behaving by philipbailey

and:  <code> code here </code>

  • Please read these before you post! —
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (4)
    As of 2014-12-27 14:28 GMT
    Find Nodes?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?

      Results (177 votes), past polls