Yikes!! More fun with definitions...

What does "declare" mean and what does "local" mean?

strict says of "strict vars":

This generates a compile-time error if you access a variable that wasn’t declared via "our" or "use vars", localized via "my()", or wasn’t fully qualified.

If "localized via "my()"" is reasonable terminology, then surely it is reasonable to say that as a result the variable is "local". And surely "local" creates a "local" variable. So it is no wonder that the gentle reader has concluded that both "my" and "local" produce "local" variables and that the declarative statements "my $var" and "local $var" both "declare" them to be "local".

It is most unfortunate that there is so much loose use of terminology.

What your example shows is that, consistent with the documentation of "strict vars", "local $var" does not "declare" the variable in a manner that satisfies the requirements of "strict vars" and that without them being satisfied an unqualified reference to the variable produces an error. The variable is none the less localized (declared to be local???) in the absence of "strict vars" and can be localized with "strict vars" in effect by using its fully qualified name.

Consider

#!/usr/bin/perl -w use strict; use warnings; use Devel::Peek; $main::x = 10; { local $main::x = 20; print "$main::x\n"; } print "$main::x\n";

Which produces

20 10

In this example, is it reasonable to say that $x has not been "declared to be local" just because it has not been declared in a manner that satisfies "strict vars" so that it can be referenced by its unqualified name?


In reply to Re^3: Difference b/w my and local var? by ig
in thread Difference b/w my and local var? by anbutechie

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.