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

Re^3: why avoid & on function call

by kcott (Archbishop)
on Dec 27, 2020 at 19:14 UTC ( [id://11125810]=note: print w/replies, xml ) Need Help??


in reply to Re^2: why avoid & on function call
in thread why avoid & on function call

"The placement of a sub is important only when you call it without parentheses, ..."

I disagree with the inclusion of the word only in that statement. Here's a situation where placement is important when parentheses are used:

$ perl -wE ' sub meaning () { 42 } say meaning(); ' 42
$ perl -wE ' say meaning(); sub meaning () { 42 } ' main::meaning() called too early to check prototype at -e line 2. 42

You can, of course, predeclare and leave the definition for later:

$ perl -wE ' sub meaning (); say meaning(); # ... later in code with other subroutine defintions sub meaning () { 42 } ' 42

— Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2024-04-23 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found