Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^4: why avoid & on function call

by LanX (Saint)
on Dec 27, 2020 at 20:41 UTC ( [id://11125825]=note: print w/replies, xml ) Need Help??


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

> Usually I add an explicit exit statement to the end of the main part of the code before the subroutines so it is obvious where the main block ends.

exit doesn't end scope.

If you have variables declared in your main part, they could accidentally leak as closures into the subs.

Using sub main { BLOCK } is one way to limit the scope.

I personally rather use a naked { BLOCK }

Like this the distinction to intentionally file-scoped variables outside this main BLOCK becomes obvious.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found