I understand what Perl is doing, but it is a bit misleading to have the variable pseudo-defined, but not fully defined. For instance, Perl knows that there is a variable called $foo in the first call, the parser has picked it out, but it does not know what it is. If you change the reference in PutFoo() from "$foo" to "$bar", all sorts of warnings go off and the program will not run. "$bar" is a deal-breaker for compilation.

The only reason I've even discovered this is because I wanted to have some "static" data for a function, but wanted to minimize the "commute" between editing the function and editing its associated data. What was irritating was that Perl insisted that my variable was "defined", but it did not contain any data. There is no warning for hashes or arrays unless you are printing them. 'strict', '-w', and 'taint' were all cool with my wacky, disordered definition. I wasn't.
#!/usr/bin/perl -wT my ($global_vars....) = (global_var_definitions); # : Continues for some time sub func1 {} sub func2 { calls FuncN(), for example } # : many functions my (%funcN_data) = ( stuff ); sub funcN { reference to %funcN_data fails silently }
The only solution is to carefully organize the order of the functions, or, uh, use the BEGIN{} solution proposed by tye, which I will have to agree, is a little out of the ordinary. I mean, it gets the job done, but at what price?

I can only assume that the reason Perl behaves this way is that it is too difficult to implement differently, or because of consensus or preference on the part of the implementor, perhaps even because of the difficulty in implementing it. Sure would be nice to have a real error, though.

In reply to Re: Re: Perl Turning a Blind Eye by tadman
in thread Perl Turning a Blind Eye by tadman

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.