Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Newbie: query about array assignment

by LanX (Canon)
on Sep 13, 2012 at 13:40 UTC ( #993493=note: print w/ replies, xml ) Need Help??


in reply to Newbie: query about array assignment

"=" has a higher precedence than ",", thats why you need the parens.

DB<104> dp @stuff = "This","That","Other"; { ((@stuff = 'This'), 'That', 'Other'); } DB<105> dp @stuff = ("This","That","Other"); { (@stuff = ('This', 'That', 'Other')); }

UPDATE: the following example shows that you (almost) never really need parens for lists, it's just precendence:

DB<111> sub list { "This","That","Other" } DB<112> @stuff = list() => ("This", "That", "Other")

Cheers Rolf

PS: don't be confused "dp" is my personal debugger-macro for using B::Deparse (with -p option to show parens)


Comment on Re: Newbie: query about array assignment
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2015-07-28 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (251 votes), past polls