First off, there is a difference between a package variable and a global variable. A package variable is accessible from outside the package, you just have to completely qualify the variable name. A global variable just means a variable visible everywhere within the current scope ... which means a variable declared at the start of a file (or package) is visible throughout that file.

Here's an example:

#!/usr/bin/env perl use 5.010_000; use strict; use warnings; { package MyTest; my $global = 'global variable'; our $package = 'package variable'; sub access_global { return $global } 1; } { package main; my $package_var = $MyTest::package; my $global_var = MyTest::access_global(); my $warning_var = eval { $MyTest::global }; say ">$_<" for $package_var, $global_var, $warning_var; } __END__ >package variable< >global variable< >< Name "MyTest::global" used only once: possible typo at /Users/io1/Work +space/example/package_variables.pl line 16. Use of uninitialized value $_ in concatenation (.) or string at /Users +/io1/Workspace/example/package_variables.pl line 18.

To get at a variable that is global within a package "MyTest" from outside "MyTest" you have to use a subroutine access_global()

As for the rest of your example, I suggest you use Class::Std to implement your inside-out class. There is a BUILD() method that you can use to initialize variables in non-standard ways.

Hope that helps =)


Smoothie, smoothie, hundre prosent naturlig!

In reply to Re^4: Use of uninitialized variables? by j1n3l0
in thread Use of uninitialized variables? by Zadeh

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.