⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perl.1

📁 早期freebsd实现
💻 1
📖 第 1 页 / 共 2 页
字号:
.\".\" This highly condensed manual page was prepared from perl.man..\".TH PERL 1 "June 30, 1993".UC 6.SH NAMEperl \- practical extraction and report language.SH SYNOPSIS.B perl[options] filename args.SH DESCRIPTION.I Perlis an interpreted language optimized for scanning arbitrary text files,extracting information from those text files, and printing reports basedon that information.It's also a good language for many system management tasks.The language is intended to be practical (easy to use, efficient, complete)rather than beautiful (tiny, elegant, minimal).It combines (in the author's opinion, anyway) some of the best features of C,\fIsed\fR, \fIawk\fR, and \fIsh\fR,so people familiar with those languages should have little difficulty with it.(Language historians will also note some vestiges of \fIcsh\fR, Pascal, andeven BASIC-PLUS.)Expression syntax corresponds quite closely to C expression syntax.Unlike most Unix utilities,.I perldoes not arbitrarily limit the size of your data\(emif you've gotthe memory,.I perlcan slurp in your whole file as a single string.Recursion is of unlimited depth.And the hash tables used by associative arrays grow as necessary to preventdegraded performance..I Perluses sophisticated pattern matching techniques to scan large amounts ofdata very quickly.Although optimized for scanning text,.I perlcan also deal with binary data, and can make dbm files look like associativearrays (where dbm is available).Setuid.I perlscripts are safer than C programsthrough a dataflow tracing mechanism which prevents many stupid security holes.If you have a problem that would ordinarily use \fIsed\fRor \fIawk\fR or \fIsh\fR, but itexceeds their capabilities or must run a little faster,and you don't want to write the silly thing in C, then.I perlmay be for you.There are also translators to turn your.I sedand.I awkscripts into.I perlscripts..PPUpon startup,.I perllooks for your script in one of the following places:.Ip 1. 4 2Specified line by line via.B \-eswitches on the command line..Ip 2. 4 2Contained in the file specified by the first filename on the command line.(Note that systems supporting the #! notation invoke interpreters this way.).Ip 3. 4 2Passed in implicitly via standard input.This only works if there are no filename arguments\(emto passarguments to a.I stdinscript you must explicitly specify a \- for the script name..PPAfter locating your script,.I perlcompiles it to an internal form.If the script is syntactically correct, it is executed..PPA single-character option may be combined with the following option, if any.This is particularly useful when invoking a script using the #! construct whichonly allows one argument.  Example:.nf.ne 2	#!/usr/bin/perl \-spi.bak	# same as \-s \-p \-i.bak	.\|.\|..fiOptions include:.TP 5.BI \-0 digitsspecifies the record separator ($/) as an octal number.If there are no digits, the null character is the separator.Other switches may precede or follow the digits.For example, if you have a version of.I findwhich can print filenames terminated by the null character, you can say this:.nf    find . \-name '*.bak' \-print0 | perl \-n0e unlink.fiThe special value 00 will cause Perl to slurp files in paragraph mode.The value 0777 will cause Perl to slurp files whole since there is nolegal character with that value..TP 5.B \-aturns on autosplit mode when used with a.B \-nor.BR \-p .An implicit split command to the @F arrayis done as the first thing inside the implicit while loop produced bythe.B \-nor.BR \-p ..nf	perl \-ane \'print pop(@F), "\en";\'is equivalent to	while (<>) {		@F = split(\' \');		print pop(@F), "\en";	}.fi.TP 5.B \-ccauses.I perlto check the syntax of the script and then exit without executing it..TP 5.BI \-druns the script under the perl debugger.See the section on Debugging..TP 5.BI \-D numbersets debugging flags.To watch how it executes your script, use.BR \-D14 .(This only works if debugging is compiled into your.IR perl .)Another nice value is \-D1024, which lists your compiled syntax tree.And \-D512 displays compiled regular expressions..TP 5.BI \-e " commandline"may be used to enter one line of script.Multiple.B \-ecommands may be given to build up a multi-line script.If.B \-eis given,.I perlwill not look for a script filename in the argument list..TP 5.BI \-i extensionspecifies that files processed by the <> construct are to be editedin-place.It does this by renaming the input file, opening the output file by thesame name, and selecting that output file as the default for print statements.The extension, if supplied, is added to the name of theold file to make a backup copy.If no extension is supplied, no backup is made.Saying \*(L"perl \-p \-i.bak \-e "s/foo/bar/;" .\|.\|. \*(R" is the same as usingthe script:.nf.ne 2	#!/usr/bin/perl \-pi.bak	s/foo/bar/;which is equivalent to.ne 14	#!/usr/bin/perl	while (<>) {		if ($ARGV ne $oldargv) {			rename($ARGV, $ARGV . \'.bak\');			open(ARGVOUT, ">$ARGV");			select(ARGVOUT);			$oldargv = $ARGV;		}		s/foo/bar/;	}	continue {	    print;	# this prints to original filename	}	select(STDOUT);.fiexcept that the.B \-iform doesn't need to compare $ARGV to $oldargv to know whenthe filename has changed.It does, however, use ARGVOUT for the selected filehandle.Note that.I STDOUTis restored as the default output filehandle after the loop..SpYou can use eof to locate the end of each input file, in case you wantto append to each file, or reset line numbering (see example under eof)..TP 5.BI \-I directorymay be used in conjunction with.B \-Pto tell the C preprocessor where to look for include files.By default /usr/include and /usr/lib/perl are searched..TP 5.BI \-l octnumenables automatic line-ending processing.  It has two effects:first, it automatically chops the line terminator when used with.B \-nor.B \-p ,and second, it assigns $\e to have the value of.I octnumso that any print statements will have that line terminator added back on.  If.I octnumis omitted, sets $\e to the current value of $/.For instance, to trim lines to 80 columns:.nf	perl -lpe \'substr($_, 80) = ""\'.fiNote that the assignment $\e = $/ is done when the switch is processed,so the input record separator can be different than the output recordseparator if the.B \-lswitch is followed by a.B \-0switch:.nf	gnufind / -print0 | perl -ln0e 'print "found $_" if -p'.fiThis sets $\e to newline and then sets $/ to the null character..TP 5.B \-ncauses.I perlto assume the following loop around your script, which makes it iterateover filename arguments somewhat like \*(L"sed \-n\*(R" or \fIawk\fR:.nf.ne 3	while (<>) {		.\|.\|.		# your script goes here	}.fiNote that the lines are not printed by default.See.B \-pto have lines printed.Here is an efficient way to delete all files older than a week:.nf	find . \-mtime +7 \-print | perl \-nle \'unlink;\'.fiThis is faster than using the \-exec switch of find because you don't have tostart a process on every filename found..TP 5.B \-pcauses.I perlto assume the following loop around your script, which makes it iterateover filename arguments somewhat like \fIsed\fR:.nf.ne 5	while (<>) {		.\|.\|.		# your script goes here	} continue {		print;	}.fiNote that the lines are printed automatically.To suppress printing use the.B \-nswitch.A.B \-poverrides a.B \-nswitch..TP 5.B \-Pcauses your script to be run through the C preprocessor beforecompilation by.IR perl .(Since both comments and cpp directives begin with the # character,you should avoid starting comments with any words recognizedby the C preprocessor such as \*(L"if\*(R", \*(L"else\*(R" or \*(L"define\*(R".).TP 5.B \-senables some rudimentary switch parsing for switches on the command lineafter the script name but before any filename arguments (or before a \-\|\-).Any switch found there is removed from @ARGV and sets the corresponding variable in the.I perlscript.The following script prints \*(L"true\*(R" if and only if the script isinvoked with a \-xyz switch..nf.ne 2	#!/usr/bin/perl \-s	if ($xyz) { print "true\en"; }.fi.TP 5.B \-Smakes.I perluse the PATH environment variable to search for the script(unless the name of the script starts with a slash).Typically this is used to emulate #! startup on machines that don'tsupport #!, in the following manner:.nf

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -