in reply to Re^5: sub fuction inside sub functioin?
in thread sub fuction inside sub functioin?

Unfortunately, that gives a warning.

I note that:

use strict ; use warnings ; our $inner = "SET" ; sub inner { my ($s) = @_ ; print "$s outermost inner \$inner=$inner\n" ; } ; print "outermost start\n" ; inner('') ; buddy('') ; wrapper('') ; buddy('') ; print "outermost end\n" ; sub wrapper { my ($s) = @_ ; print "$s wrapper entered\n" ; inner($s.' ') ; local *inner ### ; print "$s *** separate local\n" ; *inner = sub { my ($s) = @_ ; $inner ||= "NOT SET" ; print "$s innermost inner $inner\n" ; } ; inner($s.' ') ; buddy($s.' ') ; print "$s wrapper exit\n" ; } ; sub buddy { my ($s) = @_ ; print "$s buddy entered\n" ; inner($s.' ') ; print "$s buddy exit\n" ; } ;
gives:
outermost start
  outermost inner $inner=SET
  buddy entered
    outermost inner $inner=SET
  buddy exit
  wrapper entered
    outermost inner $inner=SET
Subroutine main::inner redefined at zz.pl line 29.
    innermost inner SET
    buddy entered
      innermost inner SET
    buddy exit
  wrapper exit
  buddy entered
    outermost inner $inner=SET
  buddy exit
outermost end
showing the same warning. Also the value of $inner is unaffected by the local -- which may or may not be a surprise.

But if you remove the ### in the code above, to make that line:

local *inner ; print "$s *** separate local\n" ; *inner
that gives:
outermost start
  outermost inner $inner=SET
  buddy entered
    outermost inner $inner=SET
  buddy exit
  wrapper entered
    outermost inner $inner=SET
  *** separate local
    innermost inner NOT SET
    buddy entered
      innermost inner NOT SET
    buddy exit
  wrapper exit
  buddy entered
    outermost inner $inner=SET
  buddy exit
outermost end
NB: using the stand alone local *inner is undefining all parts of *inner.

I guess that the '=' is doing special things to assign the rhs to the right part of the lhs GLOB, so this is not a run of the mill assignment. Could this be why the presence of the initialiser appears to change the effect of local on a GLOB ?

You will recall that in another thread Setting signal handlers considered unsafe? it was established that  local $SIG{ALRM} = ... that the local sets the lhs undef before the assignment takes place. Which this isn't consistent with !