Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: If you believe in Lists in Scalar Context, Clap your Hands

by moritz (Cardinal)
on Oct 23, 2008 at 19:34 UTC ( #719138=note: print w/ replies, xml ) Need Help??


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.


Comment on Re^3: If you believe in Lists in Scalar Context, Clap your Hands
Download Code
Re^4: If you believe in Lists in Scalar Context, Clap your Hands
by ikegami (Pope) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://719138]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2014-11-27 07:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (180 votes), past polls