Learning Perl Objects, References amp;amp; Modules [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Learning Perl Objects, References amp;amp; Modules [Electronic resources] - نسخه متنی

Randal L. Schwartz

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید














2.9 Packages and Lexicals


A lexical variable (a variable introduced
with my) isn't prefixed by the
current package because package variables are always
global: you can always reference a package
variable if you know its full name. A lexical variable is usually
temporary and accessible for only a portion of the program. If a
lexical variable is declared, then using that name without a package
prefix results in accessing the lexical variable. However, a package
prefix ensures that you are accessing a package variable and never a
lexical variable.

For example, suppose a subroutine within
navigation.pl declares a lexical
@homeport variable. Any mention of
@homeport will then be the newly introduced
lexical variable, but a fully qualified mention of
@Navigation::homeport accesses the package
variable instead.

package Navigation;
@homeport = (21.1, -157.525);
sub get_me_home {
my @homeport;
.. @homeport .. # refers to the lexical variable
.. @Navigation::homeport .. # refers to the package variable
}
.. @homeport .. # refers to the package variable

Obviously, this can lead to confusing
code, so you shouldn't introduce such a duplication
needlessly. The results are completely predictable, though.



/ 199