Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by ikegami (Patriarch)
on Oct 24, 2008 at 02:54 UTC ( [id://719225]=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^5: If you believe in Lists in Scalar Context, Clap your Hands
by ysth (Canon) on Oct 28, 2008 at 04:51 UTC
    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.
        The "relatively" new feature I meant is lvalue subs, yes. I wasn't saying not to use them at all; the "like that" meant to avoid using them in uncommon ways. Or do thorough testing on all perl versions you expect to use. Since I don't know of a specific problem, this counts as FUD, but I am unrepentant.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-03-28 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found