📄 perlrun.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 "PERLRUN 1".TH PERLRUN 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"perlrun \- how to execute the Perl interpreter.SH "SYNOPSIS".IX Header "SYNOPSIS"\&\fBperl\fR [\ \fB\-sTtuUWX\fR\ ] [\ \fB\-hv\fR\ ]\ [\ \fB\-V\fR[:\fIconfigvar\fR]\ ] [\ \fB\-cw\fR\ ]\ [\ \fB\-d\fR[\fBt\fR][:\fIdebugger\fR]\ ]\ [\ \fB\-D\fR[\fInumber/list\fR]\ ] [\ \fB\-pna\fR\ ]\ [\ \fB\-F\fR\fIpattern\fR\ ]\ [\ \fB\-l\fR[\fIoctal\fR]\ ]\ [\ \fB\-0\fR[\fIoctal/hexadecimal\fR]\ ] [\ \fB\-I\fR\fIdir\fR\ ]\ [\ \fB\-m\fR[\fB\-\fR]\fImodule\fR\ ]\ [\ \fB\-M\fR[\fB\-\fR]\fI'module...'\fR\ ]\ [\ \fB\-f\fR\ ] [\ \fB\-C\ [\f(BInumber/list\fB]\ \fR] [\ \fB\-P\fR\ ] [\ \fB\-S\fR\ ] [\ \fB\-x\fR[\fIdir\fR]\ ] [\ \fB\-i\fR[\fIextension\fR]\ ] [\ \fB\-eE\fR\ \fI'command'\fR\ ]\ [\ \fB\-\-\fR\ ]\ [\ \fIprogramfile\fR\ ]\ [\ \fIargument\fR\ ]....SH "DESCRIPTION".IX Header "DESCRIPTION"The normal way to run a Perl program is by making it directlyexecutable, or else by passing the name of the source file as anargument on the command line. (An interactive Perl environmentis also possible\*(--see perldebug for details on how to do that.)Upon startup, Perl looks for your program in one of the followingplaces:.IP "1." 4Specified line by line via \fB\-e\fR or \fB\-E\fR switches on the command line..IP "2." 4Contained in the file specified by the first filename on the command line.(Note that systems supporting the #! notation invoke interpreters thisway. See \*(L"Location of Perl\*(R".).IP "3." 4Passed in implicitly via standard input. This works only if there areno filename arguments\*(--to pass arguments to a STDIN-read program youmust explicitly specify a \*(L"\-\*(R" for the program name..PPWith methods 2 and 3, Perl starts parsing the input file from thebeginning, unless you've specified a \fB\-x\fR switch, in which case itscans for the first line starting with #! and containing the word\&\*(L"perl\*(R", and starts there instead. This is useful for running a programembedded in a larger message. (In this case you would indicate the endof the program using the \f(CW\*(C`_\|_END_\|_\*(C'\fR token.).PPThe #! line is always examined for switches as the line is beingparsed. Thus, if you're on a machine that allows only one argumentwith the #! line, or worse, doesn't even recognize the #! line, youstill can get consistent switch behavior regardless of how Perl wasinvoked, even if \fB\-x\fR was used to find the beginning of the program..PPBecause historically some operating systems silently chopped offkernel interpretation of the #! line after 32 characters, someswitches may be passed in on the command line, and some may not;you could even get a \*(L"\-\*(R" without its letter, if you're not careful.You probably want to make sure that all your switches fall eitherbefore or after that 32\-character boundary. Most switches don'tactually care if they're processed redundantly, but getting a \*(L"\-\*(R"instead of a complete switch could cause Perl to try to executestandard input instead of your program. And a partial \fB\-I\fR switchcould also cause odd results..PPSome switches do care if they are processed twice, for instancecombinations of \fB\-l\fR and \fB\-0\fR. Either put all the switches afterthe 32\-character boundary (if applicable), or replace the use of\&\fB\-0\fR\fIdigits\fR by \f(CW\*(C`BEGIN{ $/ = "\e0digits"; }\*(C'\fR..PPParsing of the #! switches starts wherever \*(L"perl\*(R" is mentioned in the line.The sequences \*(L"\-*\*(R" and \*(L"\- \*(R" are specifically ignored so that you could,if you were so inclined, say.PP.Vb 3\& #!/bin/sh \-\- # \-*\- perl \-*\- \-p\& eval \*(Aqexec perl \-wS $0 ${1+"$@"}\*(Aq\& if $running_under_some_shell;.Ve.PPto let Perl see the \fB\-p\fR switch..PPA similar trick involves the \fBenv\fR program, if you have it..PP.Vb 1\& #!/usr/bin/env perl.Ve.PPThe examples above use a relative path to the perl interpreter,getting whatever version is first in the user's path. If you wanta specific version of Perl, say, perl5.005_57, you should placethat directly in the #! line's path..PPIf the #! line does not contain the word \*(L"perl\*(R", the program named afterthe #! is executed instead of the Perl interpreter. This is slightlybizarre, but it helps people on machines that don't do #!, because theycan tell a program that their \s-1SHELL\s0 is \fI/usr/bin/perl\fR, and Perl will thendispatch the program to the correct interpreter for them..PPAfter locating your program, Perl compiles the entire program to aninternal form. If there are any compilation errors, execution of theprogram is not attempted. (This is unlike the typical shell script,which might run part-way through before finding a syntax error.).PPIf the program is syntactically correct, it is executed. If the programruns off the end without hitting an \fIexit()\fR or \fIdie()\fR operator, an implicit\&\f(CWexit(0)\fR is provided to indicate successful completion..Sh "#! and quoting on non-Unix systems".IX Xref "hashbang #!".IX Subsection "#! and quoting on non-Unix systems"Unix's #! technique can be simulated on other systems:.IP "\s-1OS/2\s0" 4.IX Item "OS/2"Put.Sp.Vb 1\& extproc perl \-S \-your_switches.Ve.Spas the first line in \f(CW\*(C`*.cmd\*(C'\fR file (\fB\-S\fR due to a bug in cmd.exe's`extproc' handling)..IP "MS-DOS" 4.IX Item "MS-DOS"Create a batch file to run your program, and codify it in\&\f(CW\*(C`ALTERNATE_SHEBANG\*(C'\fR (see the \fIdosish.h\fR file in the sourcedistribution for more information)..IP "Win95/NT" 4.IX Item "Win95/NT"The Win95/NT installation, when using the ActiveState installer for Perl,will modify the Registry to associate the \fI.pl\fR extension with the perlinterpreter. If you install Perl by other means (including building fromthe sources), you may have to modify the Registry yourself. Note thatthis means you can no longer tell the difference between an executablePerl program and a Perl library file..IP "Macintosh" 4.IX Item "Macintosh"Under \*(L"Classic\*(R" MacOS, a perl program will have the appropriate Creator andType, so that double-clicking them will invoke the MacPerl application.Under Mac \s-1OS\s0 X, clickable apps can be made from any \f(CW\*(C`#!\*(C'\fR script using WilSanchez' DropScript utility: http://www.wsanchez.net/software/ ..IP "\s-1VMS\s0" 4.IX Item "VMS"Put.Sp.Vb 2\& $ perl \-mysw \*(Aqf$env("procedure")\*(Aq \*(Aqp1\*(Aq \*(Aqp2\*(Aq \*(Aqp3\*(Aq \*(Aqp4\*(Aq \*(Aqp5\*(Aq \*(Aqp6\*(Aq \*(Aqp7\*(Aq \*(Aqp8\*(Aq !\& $ exit++ + ++$status != 0 and $exit = $status = undef;.Ve.Spat the top of your program, where \fB\-mysw\fR are any command line switches youwant to pass to Perl. You can now invoke the program directly, by saying\&\f(CW\*(C`perl program\*(C'\fR, or as a \s-1DCL\s0 procedure, by saying \f(CW@program\fR (or implicitlyvia \fI\s-1DCL$PATH\s0\fR by just using the name of the program)..SpThis incantation is a bit much to remember, but Perl will display it foryou if you say \f(CW\*(C`perl "\-V:startperl"\*(C'\fR..PPCommand-interpreters on non-Unix systems have rather different ideason quoting than Unix shells. You'll need to learn the specialcharacters in your command-interpreter (\f(CW\*(C`*\*(C'\fR, \f(CW\*(C`\e\*(C'\fR and \f(CW\*(C`"\*(C'\fR arecommon) and how to protect whitespace and these characters to runone-liners (see \fB\-e\fR below)..PPOn some systems, you may have to change single-quotes to double ones,which you must \fInot\fR do on Unix or Plan 9 systems. You might alsohave to change a single % to a %%..PPFor example:.PP.Vb 2\& # Unix\& perl \-e \*(Aqprint "Hello world\en"\*(Aq\&\& # MS\-DOS, etc.\& perl \-e "print \e"Hello world\en\e""\&\& # Macintosh\& print "Hello world\en"\& (then Run "Myscript" or Shift\-Command\-R)\&\& # VMS\& perl \-e "print ""Hello world\en""".Ve.PPThe problem is that none of this is reliable: it depends on thecommand and it is entirely possible neither works. If \fB4DOS\fR werethe command shell, this would probably work better:.PP.Vb 1\& perl \-e "print <Ctrl\-x>"Hello world\en<Ctrl\-x>"".Ve.PP\&\fB\s-1CMD\s0.EXE\fR in Windows \s-1NT\s0 slipped a lot of standard Unix functionality inwhen nobody was looking, but just try to find documentation for itsquoting rules..PPUnder the Macintosh, it depends which environment you are using. The MacPerlshell, or \s-1MPW\s0, is much like Unix shells in its support for severalquoting variants, except that it makes free use of the Macintosh's non-ASCIIcharacters as control characters..PPThere is no general solution to all of this. It's just a mess..Sh "Location of Perl".IX Xref "perl, location of interpreter".IX Subsection "Location of Perl"It may seem obvious to say, but Perl is useful only when users caneasily find it. When possible, it's good for both \fI/usr/bin/perl\fRand \fI/usr/local/bin/perl\fR to be symlinks to the actual binary. Ifthat can't be done, system administrators are strongly encouragedto put (symlinks to) perl and its accompanying utilities into adirectory typically found along a user's \s-1PATH\s0, or in some otherobvious and convenient place..PPIn this documentation, \f(CW\*(C`#!/usr/bin/perl\*(C'\fR on the first line of the programwill stand in for whatever method works on your system. You areadvised to use a specific path if you care about a specific version..PP.Vb 1\& #!/usr/local/bin/perl5.00554.Ve.PPor if you just want to be running at least version, place a statementlike this at the top of your program:.PP.Vb 1\& use 5.005_54;.Ve.Sh "Command Switches".IX Xref "perl, command switches command switches".IX Subsection "Command Switches"As with all standard commands, a single-character switch may beclustered with the following switch, if any..PP.Vb 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -