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

📄 perl.1

📁 早期freebsd实现
💻 1
📖 第 1 页 / 共 2 页
字号:
	#!/usr/bin/perl	eval "exec /usr/bin/perl \-S $0 $*"		if $running_under_some_shell;.fiThe system ignores the first line and feeds the script to /bin/sh,which proceeds to try to execute the.I perlscript as a shell script.The shell executes the second line as a normal shell command, and thusstarts up the.I perlinterpreter.On some systems $0 doesn't always contain the full pathname,so the.B \-Stells.I perlto search for the script if necessary.After.I perllocates the script, it parses the lines and ignores them becausethe variable $running_under_some_shell is never true.A better construct than $* would be ${1+"$@"}, which handles embedded spacesand such in the filenames, but doesn't work if the script is being interpretedby csh.In order to start up sh rather than csh, some systems may have to replace the#! line with a line containing justa colon, which will be politely ignored by perl.Other systems can't control that, and need a totally devious construct thatwill work under any of csh, sh or perl, such as the following:.nf.ne 3	eval '(exit $?0)' && eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'	& eval 'exec /usr/bin/perl -S $0 $argv:q'		if 0;.fi.TP 5.B \-ucauses.I perlto dump core after compiling your script.You can then take this core dump and turn it into an executable fileby using the undump program (not supplied).This speeds startup at the expense of some disk space (which you canminimize by stripping the executable).(Still, a "hello world" executable comes out to about 200K on my machine.)If you are going to run your executable as a set-id program then youshould probably compile it using taintperl rather than normal perl.If you want to execute a portion of your script before dumping, use thedump operator instead.Note: availability of undump is platform specific and may not be availablefor a specific port of perl..TP 5.B \-Uallows.I perlto do unsafe operations.Currently the only \*(L"unsafe\*(R" operations are the unlinking of directories whilerunning as superuser, and running setuid programs with fatal taint checksturned into warnings..TP 5.B \-vprints the version and patchlevel of your.I perlexecutable..TP 5.B \-wprints warnings about identifiers that are mentioned only once, and scalarvariables that are used before being set.Also warns about redefined subroutines, and references to undefinedfilehandles or filehandles opened readonly that you are attempting towrite on.Also warns you if you use == on values that don't look like numbers, and ifyour subroutines recurse more than 100 deep..TP 5.BI \-x directorytells.I perlthat the script is embedded in a message.Leading garbage will be discarded until the first line that startswith #! and contains the string "perl".Any meaningful switches on that line will be applied (but only onegroup of switches, as with normal #! processing).If a directory name is specified, Perl will switch to that directorybefore running the script.The.B \-xswitch only controls the the disposal of leading garbage.The script must be terminated with _\|_END_\|_ if there is trailing garbageto be ignored (the script can process any or all of the trailing garbagevia the DATA filehandle if desired)..SH ENVIRONMENT.Ip HOME 12 4Used if chdir has no argument..Ip LOGDIR 12 4Used if chdir has no argument and HOME is not set..Ip PATH 12 4Used in executing subprocesses, and in finding the script if \-Sis used..Ip PERLLIB 12 4A colon-separated list of directories in which to look for Perl libraryfiles before looking in the standard library and the current directory..Ip PERLDB 12 4The command used to get the debugger code.  If unset, uses.br	require 'perldb.pl'.PPApart from these,.I perluses no other environment variables, except to make them availableto the script being executed, and to child processes.However, scripts running setuid would do well to execute the following linesbefore doing anything else, just to keep people honest:.nf.ne 3    $ENV{\'PATH\'} = \'/bin:/usr/bin\';    # or whatever you need    $ENV{\'SHELL\'} = \'/bin/sh\' if $ENV{\'SHELL\'} ne \'\';    $ENV{\'IFS\'} = \'\' if $ENV{\'IFS\'} ne \'\';.fi.SH FILES/tmp/perl\-eXXXXXX	temporary file for.B \-ecommands..SH SEE ALSOThe complete perl documentation can be found in theUNIX System manager's Manual (SMM:19)..bra2p	awk to perl translator.brs2p	sed to perl translator.SH DIAGNOSTICSCompilation errors will tell you the line number of the error, with anindication of the next token or token type that was to be examined.(In the case of a script passed to.I perlvia.B \-eswitches, each.B \-eis counted as one line.).PPSetuid scripts have additional constraints that can produce error messagessuch as \*(L"Insecure dependency\*(R".See the section on setuid scripts..SH TRAPSAccustomed.IR awkusers should take special note of the following:.Ip * 4 2Semicolons are required after all simple statements in.I perl(except at the end of a block).Newline is not a statement delimiter..Ip * 4 2Curly brackets are required on ifs and whiles..Ip * 4 2Variables begin with $ or @ in.IR perl ..Ip * 4 2Arrays index from 0 unless you set $[.Likewise string positions in substr() and index()..Ip * 4 2You have to decide whether your array has numeric or string indices..Ip * 4 2Associative array values do not spring into existence upon mere reference..Ip * 4 2You have to decide whether you want to use string or numeric comparisons..Ip * 4 2Reading an input line does not split it for you.  You get to split it yourselfto an array.And the.I splitoperator has different arguments..Ip * 4 2The current input line is normally in $_, not $0.It generally does not have the newline stripped.($0 is the name of the program executed.).Ip * 4 2$<digit> does not refer to fields\(emit refers to substrings matched by the lastmatch pattern..Ip * 4 2The.I printstatement does not add field and record separators unless you set$, and $\e..Ip * 4 2You must open your files before you print to them..Ip * 4 2The range operator is \*(L".\|.\*(R", not comma.(The comma operator works as in C.).Ip * 4 2The match operator is \*(L"=~\*(R", not \*(L"~\*(R".(\*(L"~\*(R" is the one's complement operator, as in C.).Ip * 4 2The exponentiation operator is \*(L"**\*(R", not \*(L"^\*(R".(\*(L"^\*(R" is the XOR operator, as in C.).Ip * 4 2The concatenation operator is \*(L".\*(R", not the null string.(Using the null string would render \*(L"/pat/ /pat/\*(R" unparsable,since the third slash would be interpreted as a division operator\(emthetokener is in fact slightly context sensitive for operators like /, ?, and <.And in fact, . itself can be the beginning of a number.).Ip * 4 2.IR Next ,.I exitand.I continuework differently..Ip * 4 2The following variables work differently.nf	  Awk	\h'|2.5i'Perl	  ARGC	\h'|2.5i'$#ARGV	  ARGV[0]	\h'|2.5i'$0	  FILENAME\h'|2.5i'$ARGV	  FNR	\h'|2.5i'$. \- something	  FS	\h'|2.5i'(whatever you like)	  NF	\h'|2.5i'$#Fld, or some such	  NR	\h'|2.5i'$.	  OFMT	\h'|2.5i'$#	  OFS	\h'|2.5i'$,	  ORS	\h'|2.5i'$\e	  RLENGTH	\h'|2.5i'length($&)	  RS	\h'|2.5i'$/	  RSTART	\h'|2.5i'length($\`)	  SUBSEP	\h'|2.5i'$;.fi.Ip * 4 2When in doubt, run the.I awkconstruct through a2p and see what it gives you..PPCerebral C programmers should take note of the following:.Ip * 4 2Curly brackets are required on ifs and whiles..Ip * 4 2You should use \*(L"elsif\*(R" rather than \*(L"else if\*(R".Ip * 4 2.I Breakand.I continuebecome.I lastand.IR next ,respectively..Ip * 4 2There's no switch statement..Ip * 4 2Variables begin with $ or @ in.IR perl ..Ip * 4 2Printf does not implement *..Ip * 4 2Comments begin with #, not /*..Ip * 4 2You can't take the address of anything..Ip * 4 2ARGV must be capitalized..Ip * 4 2The \*(L"system\*(R" calls link, unlink, rename, etc. return nonzero for success, not 0..Ip * 4 2Signal handlers deal with signal names, not numbers..PPSeasoned.I sedprogrammers should take note of the following:.Ip * 4 2Backreferences in substitutions use $ rather than \e..Ip * 4 2The pattern matching metacharacters (, ), and | do not have backslashes in front..Ip * 4 2The range operator is .\|. rather than comma..PPSharp shell programmers should take note of the following:.Ip * 4 2The backtick operator does variable interpretation without regard to thepresence of single quotes in the command..Ip * 4 2The backtick operator does no translation of the return value, unlike csh..Ip * 4 2Shells (especially csh) do several levels of substitution on each command line..I Perldoes substitution only in certain constructs such as double quotes,backticks, angle brackets and search patterns..Ip * 4 2Shells interpret scripts a little bit at a time..I Perlcompiles the whole program before executing it..Ip * 4 2The arguments are available via @ARGV, not $1, $2, etc..Ip * 4 2The environment is not automatically made available as variables..SH BUGS.PP.I Perlis at the mercy of your machine's definitions of various operationssuch as type casting, atof() and sprintf()..PPIf your stdio requires a seek or eof between reads and writes on a particularstream, so does.IR perl .(This doesn't apply to sysread() and syswrite().).PPWhile none of the built-in data types have any arbitrary size limits (apartfrom memory size), there are still a few arbitrary limits:a given identifier may not be longer than 255 characters,and no component of your PATH may be longer than 255 if you use \-S.A regular expression may not compile to more than 32767 bytes internally..PP.I Perlactually stands for Pathologically Eclectic Rubbish Lister, but don't tellanyone I said that..SH AUTHORLarry Wall <lwall@netlabs.com>.brMS-DOS port by Diomidis Spinellis <dds@cc.ic.ac.uk>

⌨️ 快捷键说明

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