in reply to mod_perl: variable $end will not stay shared (nested subroutines problem)

Yesterday there was much discussion among the senior monks of "will not stay shared" errors, and I was privileged to listen to their wisdom.

In your case, you are seeing this error because you declare the lexical variable 'my $bufsis' outside your named subroutine read_size() but $bufsis then appears inside your named subroutine. (Variables declared using my() are called lexical in Perlish.)

When a lexical variable and a named subroutine are in the same lexical scope, and the lexical variable is declared outside the subroutine but appears inside the subroutine you get a message such as yours.

Solutions? Well, you can make the lexical variable a global one. Or you can pass the lexical variable as a parameter to your subroutine. Or you can make your subroutine anonymous instead of named. There are a lot of workarounds, but I don't know which is the best. I think that Tye or Tilly yesterday proposed something along the lines of the first solution, make the lexical variable a non-lexical one.

  • Comment on Re: mod_perl: variable $end will not stay shared (nested subroutines problem)