When you are using the strict pragma, Perl is, in a sense, enforcing the use of fully qualified variable names. All variables belong to a package, if even only the main package. So when you use strict and initialize a variable with <text>my</text>, essentially Perl is identifying that variable as part of the current package(like $package::var - NOTE - WHen no package is explicitly declared, the package is 'main').

So:

#!/usr/bin/perl package Test; use strict; my $var;
UPDATE: I originally posted that my $var was equivalent to $Test::var. That is incorrect however, I've since learned that lexical variables are not package variables at all. I offer as proof:
package Amel; use strict; $Amel::var = "Dan"; my $var = "Balaban"; print $Amel::var, " $var\n";
'local' on the other hand does not actually initialize variables, and certainly does nothing to fully qualify the variable name with a package.

As far as the error goes:

Global symbol "$var" requires explicit package name at - line 3.

When Perl says 'explicit package name', technically you could fix your problem my preceding all of your variables with the name of the current package instead of using 'my', but you'd have to do that every time you use the variable...blech!

But just so you understand:

#!/usr/bin/perl use strict; $main::var = "string"; print $main::var, "\n";

Amel - f.k.a. - kel


In reply to Re: Is local a declaration? by dsb
in thread Is local a declaration? by Anonymous Monk

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.