Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: sub execution order aka missing semicolon after sub call

by johngg (Canon)
on Apr 07, 2016 at 10:41 UTC ( [id://1159799]=note: print w/replies, xml ) Need Help??


in reply to Re^2: sub execution order aka missing semicolon after sub call
in thread sub execution order aka missing semicolon after sub call

The idea with the habit of adding () after all sub-calls is indeed a very good idea.

There is a special case where the use of parentheses is not appropriate. If you call subB from within subA using the syntax &subB with no parentheses then the argument list of subA will be passed to subB. See this node for an example.

The subroutine doesn't actually have to be called from within another subroutine; it is the content of @_ that matters, as demonstrated by the following code.

$ perl -Mstrict -Mwarnings -E ' @_ = @ARGV; ∑ sub sum { my $sum; $sum += $_ for @_; say $sum; }' 1 2 3 4 5 15 $

I hope this is of interest.

Cheers,

JohnGG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found