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.


In reply to Re: mod_perl: variable $end will not stay shared (nested subroutines problem) by sierrathedog04
in thread mod_perl: variable $end will not stay shared (nested subroutines problem) by princepawn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.