http://www.perlmonks.org?node_id=719138


in reply to Re^2: If you believe in Lists in Scalar Context, Clap your Hands
in thread If you believe in Lists in Scalar Context, Clap your Hands

An array is everything that could be used as an lvalue (perhaps with the exception of :lvalue subs, haven't tried those), independently of you actually use it as an lvalue.

That definition so far helped in all real-world cases that I've look at.

Replies are listed 'Best First'.
Re^4: If you believe in Lists in Scalar Context, Clap your Hands
by ikegami (Patriarch) on Oct 24, 2008 at 02:54 UTC

    perhaps with the exception of :lvalue subs, haven't tried those

    lvalue subs are called in scalar context, so they can't return a list.

    use strict; use warnings; my ($i,$j); sub f :lvalue { ($i,$j) } f() = (4,5); print("$i,$j\n");
    Useless use of a constant in void context at script.pl line 5. Use of uninitialized value in concatenation (.) or string at script.pl + line 6. ,5
      Wrong. Don't forget that plain = is the scalar assignment operator, unless there is a hash or array on the left. ()= is the list assignment operator:
      $ perl use strict; use warnings; my ($i,$j); sub f :lvalue { ($i,$j) } (f()) = (4,5); print("$i,$j\n"); __END__ 4,5
      However, I would be very leery of using a relatively new feature like that that has probably not been used much in that way.

        Ah thanks, (although, not just "()=" is the list assignment operator).

        I would be very leery of using lvalue subs *in any way*.

        Which relative new feature are you refering to? lvalue subs have been around since at least 5.6.0, and maybe even before that.