Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Function Prototype Context Conversion

by ariels (Curate)
on Jun 12, 2002 at 20:05 UTC ( [id://173988]=note: print w/replies, xml ) Need Help??


in reply to Function Prototype Context Conversion

...why can't @foo be treated as an implicit list for DWIM purposes?
Because you asked Perl to treat it specially!

Think of it like this: when you say sub foo($), you're telling Perl to convert to a scalar the first arg of foo. When you say ``foo(@foo)'', you know that @foo has only one element (and therefore can assume you know what you mean), but perl doesn't. All perl looks at is the syntax of your code: an array is being used in a scalar context. So it gets converted to a scalar. Your "rule" for converting only works for 1-element lists; Perl's rule for converting an array to a scalar works for any size array.

It looks like another behaviour of Perl's conversion semantics that manages to confuse people.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 07:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found