in reply to Re: difference between array and list in perl
in thread difference between array and list in perl

although the list (list1, list2, list3, list4) is questionable, since it contains bare words which might be interpreteted as subroutine calls
Whether they are subroutine calls or not doesn't matter. It's a list because of the context - the RHS of a list assignment is always a list. The fact the assignment is a list assignment is caused by the LHS being an array.
qw returns a list
No, it doesn't. In Perl, it's not the operation (operator, subroutine, function) that determines whether a list or a scalar is returned - it's the context. It's always the context. qw in scalar context cannot return a list - there are no lists in scalar context.1
in an old release it used to return an array
In which release was that? And what does "returning an array" mean? Could I push on it? Slice from it? Did it have a name? Perhaps you're confused by the fact in earlier releases qw was calculated at run-time (by doing a split), and nowadays qw is calculated at compile time.
You can assign to a list on the left side, provided the list only consists of variables....
...then assign from the array into the three variables $speed, $colour, $animal arranged in a list.
You're contradiction yourself. First you say it assigns to a list, then you say it assigns to a three variables. It's actually the latter that happens.

1Who will be the first one to claim this time there's such a thing as lists in scalar context?

Replies are listed 'Best First'.
Re^3: difference between array and list in perl
by ikegami (Patriarch) on Jan 17, 2010 at 07:23 UTC

    Who will be the first one to claim this time there's such a thing as lists in scalar context?

    There is. Here's one:

    >perl -MO=Concise -e"$x = (4,5,6)" 2>&1 | find "list" 5 <@> list sKP ->6 ^ ^ | | list scalar context

    That's why it's clearer to say "an expression cannot return a list in scalar context". In the above example, the list evaluates to the scalar 6.

    Since you know better, why do you use such a needlessly confusing sentence?

Re^3: difference between array and list in perl
by LanX (Saint) on Jan 17, 2010 at 01:02 UTC
    > there are no lists in scalar context

    This is - as usual - a definition conflict!

    As I already pointed out there are (at least) two widespread interpretations of what "LIST" mean:

  • a literal comma separated sequence of expressions visible in source code
  • the realization for passing theses values at run time through an internal stack

    Take this example code:

     perl -e 'print scalar ($a++,"b","c"), $a'

    Following your explanation one might think that $a should never be incremented, since the "list" (the stack) is never built!

    But actually one gets c1 as output, since the "list" (the sequence) is evaluated step by step

    Cheers Rolf

    UPDATE: shortened post

      the realization for passing theses values at run time through an internal stack
      Don't confuse implementation (perl) with the language (Perl)! Otherwise, you'd have to start claiming Perl has pointers!
      perl -e 'print scalar ($a++,"b","c"), $a'

      Following your explanation one might think that $a should never be incremented, since the "list" (the stack) is never built!

      Bollocks! What you have here is the scalar comma operator. From perlop:
      Binary "," is the comma operator. In scalar context it evaluates its left argument, throws that value away, then evaluates its right argument and returns that value. This is just like C’s comma operator.