in reply to Re: Variable will not stay shared in subroutine
in thread Variable will not stay shared in subroutine

The correct solution is not to declare a named subroutine inside a named subroutine.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
  • Comment on Re^2: Variable will not stay shared in subroutine

Replies are listed 'Best First'.
Re^3: Variable will not stay shared in subroutine
by Anonymous Monk on Feb 02, 2018 at 17:53 UTC
    I found this thread when looking for explanation for this message. In my case the solution is using "our" instead of "my". As a side effect the variable is a global with limited visibility.
      You've just treated the symptoms, not the cause. In Perl, it makes no sense to define a named subroutine inside a named subroutine, as the nested subroutine is still globally visible.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      If you really need a nested subroutine for the current scope only, then better use an anonymous one, like already described here by tilly.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Wikisyntax for the Monastery