📄 perlmod.1
字号:
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Vb \" Begin verbatim text.ft CW.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings. \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote. \*(C+ will.\" give a nicer C++. Capital omega is used to do unbreakable dashes and.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,.\" nothing in troff, for use with C<>..tr \(*W-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\. ds -- \(*W-. ds PI pi. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch. ds L" "". ds R" "". ds C` "". ds C' ""'br\}.el\{\. ds -- \|\(em\|. ds PI \(*p. ds L" ``. ds R" '''br\}.\".\" Escape single quotes in literal strings from groff's Unicode transform..ie \n(.g .ds Aq \(aq.el .ds Aq '.\".\" If the F register is turned on, we'll generate index entries on stderr for.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index.\" entries marked with X<> in POD. Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\. de IX. tm Index:\\$1\t\\n%\t"\\$2"... nr % 0. rr F.\}.el \{\. de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear. Run. Save yourself. No user-serviceable parts.. \" fudge factors for nroff and troff.if n \{\. ds #H 0. ds #V .8m. ds #F .3m. ds #[ \f1. ds #] \fP.\}.if t \{\. ds #H ((1u-(\\\\n(.fu%2u))*.13m). ds #V .6m. ds #F 0. ds #[ \&. ds #] \&.\}. \" simple accents for nroff and troff.if n \{\. ds ' \&. ds ` \&. ds ^ \&. ds , \&. ds ~ ~. ds /.\}.if t \{\. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u". ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}. \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E. \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'. \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\. ds : e. ds 8 ss. ds o a. ds d- d\h'-1'\(ga. ds D- D\h'-1'\(hy. ds th \o'bp'. ds Th \o'LP'. ds ae ae. ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "PERLMOD 1".TH PERLMOD 1 "2007-12-18" "perl v5.10.0" "Perl Programmers Reference Guide".\" For nroff, turn off justification. Always turn off hyphenation; it makes.\" way too many mistakes in technical documents..if n .ad l.nh.SH "NAME"perlmod \- Perl modules (packages and symbol tables).SH "DESCRIPTION".IX Header "DESCRIPTION".Sh "Packages".IX Xref "package namespace variable, global global variable global".IX Subsection "Packages"Perl provides a mechanism for alternative namespaces to protectpackages from stomping on each other's variables. In fact, there'sreally no such thing as a global variable in Perl. The packagestatement declares the compilation unit as being in the givennamespace. The scope of the package declaration is from thedeclaration itself through the end of the enclosing block, \f(CW\*(C`eval\*(C'\fR,or file, whichever comes first (the same scope as the \fImy()\fR and\&\fIlocal()\fR operators). Unqualified dynamic identifiers will be inthis namespace, except for those few identifiers that if unqualified,default to the main package instead of the current one as describedbelow. A package statement affects only dynamic variables\*(--includingthose you've used \fIlocal()\fR on\*(--but \fInot\fR lexical variables createdwith \fImy()\fR. Typically it would be the first declaration in a fileincluded by the \f(CW\*(C`do\*(C'\fR, \f(CW\*(C`require\*(C'\fR, or \f(CW\*(C`use\*(C'\fR operators. You canswitch into a package in more than one place; it merely influenceswhich symbol table is used by the compiler for the rest of thatblock. You can refer to variables and filehandles in other packagesby prefixing the identifier with the package name and a doublecolon: \f(CW$Package::Variable\fR. If the package name is null, the\&\f(CW\*(C`main\*(C'\fR package is assumed. That is, \f(CW$::sail\fR is equivalent to\&\f(CW$main::sail\fR..PPThe old package delimiter was a single quote, but double colon is now thepreferred delimiter, in part because it's more readable to humans, andin part because it's more readable to \fBemacs\fR macros. It also makes \*(C+programmers feel like they know what's going on\*(--as opposed to using thesingle quote as separator, which was there to make Ada programmers feellike they knew what was going on. Because the old-fashioned syntax is stillsupported for backwards compatibility, if you try to use a string like\&\f(CW"This is $owner\*(Aqs house"\fR, you'll be accessing \f(CW$owner::s\fR; that is,the \f(CW$s\fR variable in package \f(CW\*(C`owner\*(C'\fR, which is probably not what you meant.Use braces to disambiguate, as in \f(CW"This is ${owner}\*(Aqs house"\fR..IX Xref ":: '".PPPackages may themselves contain package separators, as in\&\f(CW$OUTER::INNER::var\fR. This implies nothing about the order ofname lookups, however. There are no relative packages: all symbolsare either local to the current package, or must be fully qualifiedfrom the outer package name down. For instance, there is nowherewithin package \f(CW\*(C`OUTER\*(C'\fR that \f(CW$INNER::var\fR refers to\&\f(CW$OUTER::INNER::var\fR. \f(CW\*(C`INNER\*(C'\fR refers to a totallyseparate global package..PPOnly identifiers starting with letters (or underscore) are storedin a package's symbol table. All other symbols are kept in package\&\f(CW\*(C`main\*(C'\fR, including all punctuation variables, like \f(CW$_\fR. In addition,when unqualified, the identifiers \s-1STDIN\s0, \s-1STDOUT\s0, \s-1STDERR\s0, \s-1ARGV\s0,\&\s-1ARGVOUT\s0, \s-1ENV\s0, \s-1INC\s0, and \s-1SIG\s0 are forced to be in package \f(CW\*(C`main\*(C'\fR,even when used for other purposes than their built-in ones. If youhave a package called \f(CW\*(C`m\*(C'\fR, \f(CW\*(C`s\*(C'\fR, or \f(CW\*(C`y\*(C'\fR, then you can't use thequalified form of an identifier because it would be instead interpretedas a pattern match, a substitution, or a transliteration..IX Xref "variable, punctuation".PPVariables beginning with underscore used to be forced into packagemain, but we decided it was more useful for package writers to be ableto use leading underscore to indicate private variables and method names.However, variables and functions named with a single \f(CW\*(C`_\*(C'\fR, such as\&\f(CW$_\fR and \f(CW\*(C`sub _\*(C'\fR, are still forced into the package \f(CW\*(C`main\*(C'\fR. See also\&\*(L"Technical Note on the Syntax of Variable Names\*(R" in perlvar..PP\&\f(CW\*(C`eval\*(C'\fRed strings are compiled in the package in which the \fIeval()\fR wascompiled. (Assignments to \f(CW$SIG{}\fR, however, assume the signalhandler specified is in the \f(CW\*(C`main\*(C'\fR package. Qualify the signal handlername if you wish to have a signal handler in a package.) For anexample, examine \fIperldb.pl\fR in the Perl library. It initially switchesto the \f(CW\*(C`DB\*(C'\fR package so that the debugger doesn't interfere with variablesin the program you are trying to debug. At various points, however, ittemporarily switches back to the \f(CW\*(C`main\*(C'\fR package to evaluate variousexpressions in the context of the \f(CW\*(C`main\*(C'\fR package (or wherever you camefrom). See perldebug..PPThe special symbol \f(CW\*(C`_\|_PACKAGE_\|_\*(C'\fR contains the current package, but cannot(easily) be used to construct variable names..PPSee perlsub for other scoping issues related to \fImy()\fR and \fIlocal()\fR,and perlref regarding closures..Sh "Symbol Tables".IX Xref "symbol table stash %:: %main:: typeglob glob alias".IX Subsection "Symbol Tables"The symbol table for a package happens to be stored in the hash of thatname with two colons appended. The main symbol table's name is thus\&\f(CW%main::\fR, or \f(CW%::\fR for short. Likewise the symbol table for the nestedpackage mentioned earlier is named \f(CW%OUTER::INNER::\fR..PPThe value in each entry of the hash is what you are referring to when youuse the \f(CW*name\fR typeglob notation. In fact, the following have the sameeffect, though the first is more efficient because it does the symboltable lookups at compile time:.PP.Vb 2\& local *main::foo = *main::bar;\& local $main::{foo} = $main::{bar};.Ve.PP(Be sure to note the \fBvast\fR difference between the second line aboveand \f(CW\*(C`local $main::foo = $main::bar\*(C'\fR. The former is accessing the hash\&\f(CW%main::\fR, which is the symbol table of package \f(CW\*(C`main\*(C'\fR. The latter issimply assigning scalar \f(CW$bar\fR in package \f(CW\*(C`main\*(C'\fR to scalar \f(CW$foo\fR ofthe same package.).PPYou can use this to print out all the variables in a package, forinstance. The standard but antiquated \fIdumpvar.pl\fR library andthe \s-1CPAN\s0 module Devel::Symdump make use of this..PPAssignment to a typeglob performs an aliasing operation, i.e.,.PP.Vb 1\& *dick = *richard;.Ve.PPcauses variables, subroutines, formats, and file and directory handlesaccessible via the identifier \f(CW\*(C`richard\*(C'\fR also to be accessible via theidentifier \f(CW\*(C`dick\*(C'\fR. If you want to alias only a particular variable orsubroutine, assign a reference instead:.PP.Vb 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -