http://www.perlmonks.org?node_id=801215

talexb has asked for the wisdom of the Perl Monks concerning the following question:

Just wondering if the following definition of a sub within a sub is good form or not:

#!/usr/bin/perl -w # # Declare (and call) a sub within a sub. use strict; use warnings; { print "In the mainline.\n"; sub level1 { print "Inside level1!\n"; } level1(); print "Finished!\n"; }
It seems that perlcritic isn't happy with it:
foo@bar:~/dev$ perlcritic --severity=4 subinsub.pl Subroutine does not end with "return" at line 11, column 5. See page +197 of PBP. (Severity: 4)
I think this means that it thinks I'm defining a new sub, the old one wasn't terminated properly.

It does produce the output I was expecting:

foo@bar:~/dev$ perl -w subinsub.pl In the mainline. Inside level1! Finished!
Thoughts? Feedback?

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds