Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Empty List miracle(1)

by ikegami (Patriarch)
on Apr 30, 2010 at 14:50 UTC ( [id://837794]=note: print w/replies, xml ) Need Help??


in reply to Re: Empty List miracle(1)
in thread Empty List miracle(1)

Yes, but not for the reason you're implying. You're thinking @a is evaluated in scalar context when it's not. Both operands of the list assignment (@a and empty_listX()) are evaluated in list context.

If @a is an operand of the list assignment, what's the operand of the scalar() pseudo-operator? The list assignment. scalar() causes the list assignment to be evaluated in scalar context. In scalar context, the list assignment operator returns the number of elements returned by its right hand side operand.

Since it doesn't matter to what you are assigning, you could just as easily have written

print(scalar(()=empty_list1()),"\n"); # 0 print(scalar(()=empty_list2()),"\n"); # 0 print(scalar(()=empty_list3()),"\n"); # 0 print(scalar(()=(4..6) ),"\n"); # 3

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-25 14:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found