in reply to Re^3: parse lisp style config
in thread parse lisp style config

nnested subs provide some more abstraction ability

Not in Perl.

Whether nested or not, the following two snippets are equivalent:[1]

sub foo { ... }
BEGIN { *foo = sub { ... }; }

As such,

As you can see, you gain no abstraction or other benefits. Everything about it is bad.

That said, none of this applies to lexical inner subs. This is fine:

sub outer { ... my sub inner { ... } ... }

  1. Exception: The first has a name attached to the sub itself, while the second doesn't. This difference will affect croak and strack traces. I could have used Sub::Util's set_subname to correct this, but loading the module would introduce a new difference.

Replies are listed 'Best First'.
Re^5: parse lisp style config
by vincentaxhe (Scribe) on Nov 29, 2024 at 01:38 UTC
    I test to confirm it, Inner sub is not private. The only benefit may be an reminder inner sub will be only called inside.

      Just use already-mentioned my sub name { ... } instead or sub name { ... } and you will have an actual private inner sub without the drawbacks.

        thanks for emphasize it, I did overlook 'my sub ..', I did not know it is valid, I tried it, but for recursion subs it complains not defined.