It's one of my major peeves with Perl5: that inner subs don't work it is as reasonable to expect. The way they work in Javascript, for example.

It's the reason why you cannot use "my" variables in the top level of source files for mod_perl, when using Apache::Registry, the easy route from CGI to mod_perl.

There are articles on how to fix variables for inner subroutines, but the fact that you even need to worry about it is a major counterpoint against Perl, in my opinion.

The reason, as far as I gather, is because BEGIN (and related) blocks are actually subs, that are executed once; you can even use the syntax

sub BEGIN { ... }
and subs defined in BEGIN blocks are global subs.

And, Larry Wall and other prominent figures have said, years ago, that it'll never be "fixed". Because it is so by design.


In reply to Re^2: Inner subroutines? by bart
in thread Inner subroutines? by wsppan

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.