Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by ikegami (Pope)
on Oct 24, 2008 at 02:54 UTC ( #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


Comment on Re^4: If you believe in Lists in Scalar Context, Clap your Hands
Select or Download Code
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
Node Status?
node history
Node Type: note [id://719225]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-09-22 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (178 votes), past polls