आप Constants.pm
के शीर्ष पर इस डाल सकते हैं:
package main;
इस मामले में सभी चर आप main
नाम स्थान में हो जाएगा निर्धारित करें:
$main::x
या आप बहादुर महसूस कर रहे हैं, तो :
package;
इस मामले में सभी चर आप डब्ल्यू परिभाषित बीमार एक खाली नाम स्थान में हो:
$::x
ध्यान दें कि कोई नाम स्थान के साथ package
का उपयोग कर हतोत्साहित किया जाता है, और जाहिरा तौर पर पर्ल के कुछ संस्करणों में बहिष्कार किया जाएगा। नीचे उद्धरण देखें।
man perlfunc
से हवाला देते हुए:
package NAMESPACE
package Declares the compilation unit as being in the given
namespace. The scope of the package declaration is
from the declaration itself through the end of the
enclosing block, file, or eval (the same as the "my"
operator). All further unqualified dynamic identifiers
will be in this namespace. A package statement affects
only dynamic variables--including those you've used
"local" on--but not lexical variables, which are cre?
ated with "my". Typically it would be the first decla?
ration in a file to be included by the "require" or
"use" operator. You can switch into a package in more
than one place; it merely influences which symbol table
is used by the compiler for the rest of that block.
You can refer to variables and filehandles in other
packages by prefixing the identifier with the package
name and a double colon: $Package::Variable. If the
package name is null, the "main" package as assumed.
That is, $::sail is equivalent to $main::sail (as well
as to $main'sail, still seen in older code).
If NAMESPACE is omitted, then there is no current pack?
age, and all identifiers must be fully qualified or
lexicals. However, you are strongly advised not to
make use of this feature. Its use can cause unexpected
behaviour, even crashing some versions of Perl. It is
deprecated, and will be removed from a future release.
संपादित करें: इस सवाल के साथ-साथ उपयोगी हो सकता है: How do I use constants from a Perl module?
स्रोत
2009-02-08 11:31:25
धन्यवाद। मुझे वास्तव में क्या चाहिए "मुख्य" को छोड़ने का टुकड़ा। – Lev
अगर मैं वास्तव में काम करता हूं तो मैं उत्सुक हूं। यदि ऐसा होता है, तो मैं उत्तर के शीर्ष पर अस्वीकरण हटा दूंगा। –
यह स्थिरांक को मुख्य :: में रखता है, लेकिन अब आपको सभी स्थिरांक को मुख्य :: –