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:
It seems that perlcritic isn't happy with it:#!/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"; }
I think this means that it thinks I'm defining a new sub, the old one wasn't terminated properly.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)
It does produce the output I was expecting:
Thoughts? Feedback?foo@bar:~/dev$ perl -w subinsub.pl In the mainline. Inside level1! Finished!
Back to
Seekers of Perl Wisdom