Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What benefit has the "sub main ... &main();" approach (sub-main-pattern) in Perl?

Tags:

main

perl

A few years back, I have adopted the following "pattern" for all except the most simple of my Perl scripts: (I don't even remember where I saw it first, it certainly wasn't my genuine idea.)

use strict;
...
sub main {
  ...
}
... possibly more subs ...

... at the end of the file:
#############
# Call main #
&main();
#############

Is there any benefit to this? I find the code a little cleaner, but otherwise I'm not sure this has any purpose other that to make the C programmer in me happy :-)

Any insights from Perl experts and power users appreciated. (I am certainly neither)

like image 648
Martin Ba Avatar asked Jul 20 '11 15:07

Martin Ba


People also ask

What is a Sub Main?

Definition of submain : a main (as in a sewer, gas, electrical, or drainage system) having a number of lesser mains feeding into or branching from it but being itself subsidiary to a larger main.

What is a sub mains cable?

A sub-main electrical circuit can be defined as a circuit connected directly from the main LV switchboard to a sub-main distribution panel or a rising main for final connection of the minor current-using equipment.

What is a sub main distribution board?

Sub main distribution boards are also referred to as MCCB panels. A typical SMDB is equipped with MCCBs as incomer and MCCBs as outgoings. MCCB incomer is connected to upstream Main Distribution Board whereas MCCB outgoings are connected to downstream loads. These MCCBs wall mount with user friendly arrangements.


1 Answers

It's a known idiom to limit scope. This is discussed in https://stackoverflow.com/q/1183876#comment-1012787 ff. and http://use.perl.org/comments.pl?sid=43991&cid=70918 ff.

like image 103
daxim Avatar answered Nov 06 '22 01:11

daxim