📄 perlvar.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 "PERLVAR 1".TH PERLVAR 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"perlvar \- Perl predefined variables.SH "DESCRIPTION".IX Header "DESCRIPTION".Sh "Predefined Names".IX Subsection "Predefined Names"The following names have special meaning to Perl. Most punctuation names have reasonable mnemonics, or analogs in theshells. Nevertheless, if you wish to use long variable names,you need only say.PP.Vb 1\& use English;.Ve.PPat the top of your program. This aliases all the short names to the longnames in the current package. Some even have medium names, generallyborrowed from \fBawk\fR. In general, it's best to use the.PP.Vb 1\& use English \*(Aq\-no_match_vars\*(Aq;.Ve.PPinvocation if you don't need \f(CW$PREMATCH\fR, \f(CW$MATCH\fR, or \f(CW$POSTMATCH\fR, as it avoidsa certain performance hit with the use of regular expressions. SeeEnglish..PPVariables that depend on the currently selected filehandle may be set bycalling an appropriate object method on the IO::Handle object, althoughthis is less efficient than using the regular built-in variables. (Summarylines below for this contain the word \s-1HANDLE\s0.) First you must say.PP.Vb 1\& use IO::Handle;.Ve.PPafter which you may use either.PP.Vb 1\& method HANDLE EXPR.Ve.PPor more safely,.PP.Vb 1\& HANDLE\->method(EXPR).Ve.PPEach method returns the old value of the IO::Handle attribute.The methods each take an optional \s-1EXPR\s0, which, if supplied, specifies thenew value for the IO::Handle attribute in question. If not supplied,most methods do nothing to the current value\*(--except for\&\fIautoflush()\fR, which will assume a 1 for you, just to be different..PPBecause loading in the IO::Handle class is an expensive operation, you shouldlearn how to use the regular built-in variables..PPA few of these variables are considered \*(L"read-only\*(R". This means that ifyou try to assign to this variable, either directly or indirectly througha reference, you'll raise a run-time exception..PPYou should be very careful when modifying the default values of mostspecial variables described in this document. In most cases you wantto localize these variables before changing them, since if you don't,the change may affect other modules which rely on the default valuesof the special variables that you have changed. This is one of thecorrect ways to read the whole file at once:.PP.Vb 4\& open my $fh, "foo" or die $!;\& local $/; # enable localized slurp mode\& my $content = <$fh>;\& close $fh;.Ve.PPBut the following code is quite bad:.PP.Vb 4\& open my $fh, "foo" or die $!;\& undef $/; # enable slurp mode\& my $content = <$fh>;\& close $fh;.Ve.PPsince some other module, may want to read data from some file in thedefault \*(L"line mode\*(R", so if the code we have just presented has beenexecuted, the global value of \f(CW$/\fR is now changed for any other coderunning inside the same Perl interpreter..PPUsually when a variable is localized you want to make sure that thischange affects the shortest scope possible. So unless you are alreadyinside some short \f(CW\*(C`{}\*(C'\fR block, you should create one yourself. Forexample:.PP.Vb 7\& my $content = \*(Aq\*(Aq;\& open my $fh, "foo" or die $!;\& {\& local $/;\& $content = <$fh>;\& }\& close $fh;.Ve.PPHere is an example of how your own code can go broken:.PP.Vb 8\& for (1..5){\& nasty_break();\& print "$_ ";\& }\& sub nasty_break {\& $_ = 5;\& # do something with $_\& }.Ve.PPYou probably expect this code to print:.PP.Vb 1\& 1 2 3 4 5.Ve.PPbut instead you get:.PP.Vb 1\& 5 5 5 5 5.Ve.PPWhy? Because \fInasty_break()\fR modifies \f(CW$_\fR without localizing itfirst. The fix is to add \fIlocal()\fR:.PP.Vb 1\& local $_ = 5;.Ve.PPIt's easy to notice the problem in such a short example, but in morecomplicated code you are looking for trouble if you don't localizechanges to the special variables..PPThe following list is ordered by scalar variables first, then thearrays, then the hashes..ie n .IP "$ARG" 8.el .IP "\f(CW$ARG\fR" 8.IX Item "$ARG".PD 0.ie n .IP "$_" 8.el .IP "\f(CW$_\fR" 8.IX Xref "$_ $ARG".IX Item "$_".PDThe default input and pattern-searching space. The following pairs areequivalent:.Sp.Vb 2\& while (<>) {...} # equivalent only in while!\& while (defined($_ = <>)) {...}\&\& /^Subject:/\& $_ =~ /^Subject:/\&\& tr/a\-z/A\-Z/\& $_ =~ tr/a\-z/A\-Z/\&\& chomp\& chomp($_).Ve.SpHere are the places where Perl will assume \f(CW$_\fR even if youdon't use it:.RS 8.IP "\(bu" 3Various unary functions, including functions like \fIord()\fR and \fIint()\fR, as wellas the all file tests (\f(CW\*(C`\-f\*(C'\fR, \f(CW\*(C`\-d\*(C'\fR) except for \f(CW\*(C`\-t\*(C'\fR, which defaults to\&\s-1STDIN\s0..IP "\(bu" 3Various list functions like \fIprint()\fR and \fIunlink()\fR..IP "\(bu" 3The pattern matching operations \f(CW\*(C`m//\*(C'\fR, \f(CW\*(C`s///\*(C'\fR, and \f(CW\*(C`tr///\*(C'\fR when usedwithout an \f(CW\*(C`=~\*(C'\fR operator..IP "\(bu" 3The default iterator variable in a \f(CW\*(C`foreach\*(C'\fR loop if no othervariable is supplied..IP "\(bu" 3The implicit iterator variable in the \fIgrep()\fR and \fImap()\fR functions..IP "\(bu" 3The default place to put an input record when a \f(CW\*(C`<FH>\*(C'\fRoperation's result is tested by itself as the sole criterion of a \f(CW\*(C`while\*(C'\fRtest. Outside a \f(CW\*(C`while\*(C'\fR test, this will not happen..RE.RS 8.SpAs \f(CW$_\fR is a global variable, this may lead in some cases to unwantedside-effects. As of perl 5.9.1, you can now use a lexical version of\&\f(CW$_\fR by declaring it in a file or in a block with \f(CW\*(C`my\*(C'\fR. Moreover,declaring \f(CW\*(C`our $_\*(C'\fR restores the global \f(CW$_\fR in the current scope..Sp(Mnemonic: underline is understood in certain operations.).RE.ie n .IP "$a" 8.el .IP "\f(CW$a\fR" 8.IX Item "$a".PD 0.ie n .IP "$b" 8.el .IP "\f(CW$b\fR" 8.IX Xref "$a $b".IX Item "$b".PDSpecial package variables when using \fIsort()\fR, see \*(L"sort\*(R" in perlfunc.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -