Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Function Prototype Context Conversion

by ariels (Curate)
on Jun 12, 2002 at 20:05 UTC ( #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.

Comment on Re: Function Prototype Context Conversion
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (19)
As of 2015-11-30 15:25 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (774 votes), past polls