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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: subroutine inside subroutine
by jethro (Monsignor) on Jul 02, 2010 at 10:25 UTC

    by adding a ';' after use strict. The error message is a bit misleading.

    PS: Please use warnings as well. And you know that a subroutine inside another subroutine in perl is a closure? It might not always do what you expect from it (if you export a reference to it outside the enclosing subroutine).

    Updated: Reworded the warning about closure

      That definition is too vague. There is no closure here-

      sub outer { print "outer"; sub inner { print "inner" } }

      Just two package subs (in the same space).

Re: subroutine inside subroutine
by derby (Abbot) on Jul 02, 2010 at 11:36 UTC

    As to how (after adding the missing ; from use strict):

    $ perl -MO=Deparse file_containing_code_from_op use strict 'refs'; &a; sub b { use strict 'refs'; print 'as'; } sub a { use strict 'refs'; print 'as'; }

    -derby
Re: subroutine inside subroutine
by ikegami (Patriarch) on Jul 02, 2010 at 19:40 UTC
    You should avoid nested named routines. For starters, they aren't private so there's no benefit to doing so. You can also encounter subtle problems from compile-time capturing ("will not stay shared" warnings will indicate the possibility of such problems if you're using warnings).
Re: subroutine inside subroutine
by LanX (Saint) on Jul 02, 2010 at 11:23 UTC
    And what is the question?

    The code you posted is broken in multiple dimensions, no idea where to start...

    Cheers Rolf

Re: subroutine inside subroutine
by ssandv (Hermit) on Jul 02, 2010 at 18:21 UTC

    As an aside, "a" and "b" are bad choices for examples, in general, because they're already in the symbol table (for reasons of sorting). I don't think that has any effect here, but they remain poor choices.