perlfunc.pod
来自「MSYS在windows下模拟了一个类unix的终端」· POD 代码 · 共 1,621 行 · 第 1/5 页
POD
1,621 行
=head1 NAMEperlfunc - Perl builtin functions=head1 DESCRIPTIONThe functions in this section can serve as terms in an expression.They fall into two major categories: list operators and named unaryoperators. These differ in their precedence relationship with afollowing comma. (See the precedence table in L<perlop>.) Listoperators take more than one argument, while unary operators can nevertake more than one argument. Thus, a comma terminates the argument ofa unary operator, but merely separates the arguments of a listoperator. A unary operator generally provides a scalar context to itsargument, while a list operator may provide either scalar or listcontexts for its arguments. If it does both, the scalar arguments willbe first, and the list argument will follow. (Note that there can everbe only one such list argument.) For instance, splice() has three scalararguments followed by a list, whereas gethostbyname() has four scalararguments.In the syntax descriptions that follow, list operators that expect alist (and provide list context for the elements of the list) are shownwith LIST as an argument. Such a list may consist of any combinationof scalar arguments or list values; the list values will be includedin the list as if each individual element were interpolated at thatpoint in the list, forming a longer single-dimensional list value.Elements of the LIST should be separated by commas.Any function in the list below may be used either with or withoutparentheses around its arguments. (The syntax descriptions omit theparentheses.) If you use the parentheses, the simple (but occasionallysurprising) rule is this: It I<looks> like a function, therefore it I<is> afunction, and precedence doesn't matter. Otherwise it's a listoperator or unary operator, and precedence does matter. And whitespacebetween the function and left parenthesis doesn't count--so you need tobe careful sometimes: print 1+2+4; # Prints 7. print(1+2) + 4; # Prints 3. print (1+2)+4; # Also prints 3! print +(1+2)+4; # Prints 7. print ((1+2)+4); # Prints 7.If you run Perl with the B<-w> switch it can warn you about this. Forexample, the third line above produces: print (...) interpreted as function at - line 1. Useless use of integer addition in void context at - line 1.A few functions take no arguments at all, and therefore work as neitherunary nor list operators. These include such functions as C<time>and C<endpwent>. For example, C<time+86_400> always meansC<time() + 86_400>.For functions that can be used in either a scalar or list context,nonabortive failure is generally indicated in a scalar context byreturning the undefined value, and in a list context by returning thenull list.Remember the following important rule: There is B<no rule> that relatesthe behavior of an expression in list context to its behavior in scalarcontext, or vice versa. It might do two totally different things.Each operator and function decides which sort of value it would be mostappropriate to return in scalar context. Some operators return thelength of the list that would have been returned in list context. Someoperators return the first value in the list. Some operators return thelast value in the list. Some operators return a count of successfuloperations. In general, they do what you want, unless you wantconsistency.An named array in scalar context is quite different from what would atfirst glance appear to be a list in scalar context. You can't get a listlike C<(1,2,3)> into being in scalar context, because the compiler knowsthe context at compile time. It would generate the scalar comma operatorthere, not the list construction version of the comma. That means itwas never a list to start with.In general, functions in Perl that serve as wrappers for system callsof the same name (like chown(2), fork(2), closedir(2), etc.) all returntrue when they succeed and C<undef> otherwise, as is usually mentionedin the descriptions below. This is different from the C interfaces,which return C<-1> on failure. Exceptions to this rule are C<wait>,C<waitpid>, and C<syscall>. System calls also set the special C<$!>variable on failure. Other functions do not, except accidentally.=head2 Perl Functions by CategoryHere are Perl's functions (including things that look likefunctions, like some keywords and named operators)arranged by category. Some functions appear in morethan one place.=over 4=item Functions for SCALARs or stringsC<chomp>, C<chop>, C<chr>, C<crypt>, C<hex>, C<index>, C<lc>, C<lcfirst>,C<length>, C<oct>, C<ord>, C<pack>, C<q/STRING/>, C<qq/STRING/>, C<reverse>,C<rindex>, C<sprintf>, C<substr>, C<tr///>, C<uc>, C<ucfirst>, C<y///>=item Regular expressions and pattern matchingC<m//>, C<pos>, C<quotemeta>, C<s///>, C<split>, C<study>, C<qr//>=item Numeric functionsC<abs>, C<atan2>, C<cos>, C<exp>, C<hex>, C<int>, C<log>, C<oct>, C<rand>,C<sin>, C<sqrt>, C<srand>=item Functions for real @ARRAYsC<pop>, C<push>, C<shift>, C<splice>, C<unshift>=item Functions for list dataC<grep>, C<join>, C<map>, C<qw/STRING/>, C<reverse>, C<sort>, C<unpack>=item Functions for real %HASHesC<delete>, C<each>, C<exists>, C<keys>, C<values>=item Input and output functionsC<binmode>, C<close>, C<closedir>, C<dbmclose>, C<dbmopen>, C<die>, C<eof>,C<fileno>, C<flock>, C<format>, C<getc>, C<print>, C<printf>, C<read>,C<readdir>, C<rewinddir>, C<seek>, C<seekdir>, C<select>, C<syscall>,C<sysread>, C<sysseek>, C<syswrite>, C<tell>, C<telldir>, C<truncate>,C<warn>, C<write>=item Functions for fixed length data or recordsC<pack>, C<read>, C<syscall>, C<sysread>, C<syswrite>, C<unpack>, C<vec>=item Functions for filehandles, files, or directoriesC<-I<X>>, C<chdir>, C<chmod>, C<chown>, C<chroot>, C<fcntl>, C<glob>,C<ioctl>, C<link>, C<lstat>, C<mkdir>, C<open>, C<opendir>,C<readlink>, C<rename>, C<rmdir>, C<stat>, C<symlink>, C<umask>,C<unlink>, C<utime>=item Keywords related to the control flow of your perl programC<caller>, C<continue>, C<die>, C<do>, C<dump>, C<eval>, C<exit>,C<goto>, C<last>, C<next>, C<redo>, C<return>, C<sub>, C<wantarray>=item Keywords related to scopingC<caller>, C<import>, C<local>, C<my>, C<our>, C<package>, C<use>=item Miscellaneous functionsC<defined>, C<dump>, C<eval>, C<formline>, C<local>, C<my>, C<our>, C<reset>,C<scalar>, C<undef>, C<wantarray>=item Functions for processes and process groupsC<alarm>, C<exec>, C<fork>, C<getpgrp>, C<getppid>, C<getpriority>, C<kill>,C<pipe>, C<qx/STRING/>, C<setpgrp>, C<setpriority>, C<sleep>, C<system>,C<times>, C<wait>, C<waitpid>=item Keywords related to perl modulesC<do>, C<import>, C<no>, C<package>, C<require>, C<use>=item Keywords related to classes and object-orientednessC<bless>, C<dbmclose>, C<dbmopen>, C<package>, C<ref>, C<tie>, C<tied>,C<untie>, C<use>=item Low-level socket functionsC<accept>, C<bind>, C<connect>, C<getpeername>, C<getsockname>,C<getsockopt>, C<listen>, C<recv>, C<send>, C<setsockopt>, C<shutdown>,C<socket>, C<socketpair>=item System V interprocess communication functionsC<msgctl>, C<msgget>, C<msgrcv>, C<msgsnd>, C<semctl>, C<semget>, C<semop>,C<shmctl>, C<shmget>, C<shmread>, C<shmwrite>=item Fetching user and group infoC<endgrent>, C<endhostent>, C<endnetent>, C<endpwent>, C<getgrent>,C<getgrgid>, C<getgrnam>, C<getlogin>, C<getpwent>, C<getpwnam>,C<getpwuid>, C<setgrent>, C<setpwent>=item Fetching network infoC<endprotoent>, C<endservent>, C<gethostbyaddr>, C<gethostbyname>,C<gethostent>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>,C<getprotobyname>, C<getprotobynumber>, C<getprotoent>,C<getservbyname>, C<getservbyport>, C<getservent>, C<sethostent>,C<setnetent>, C<setprotoent>, C<setservent>=item Time-related functionsC<gmtime>, C<localtime>, C<time>, C<times>=item Functions new in perl5C<abs>, C<bless>, C<chomp>, C<chr>, C<exists>, C<formline>, C<glob>,C<import>, C<lc>, C<lcfirst>, C<map>, C<my>, C<no>, C<our>, C<prototype>, C<qx>, C<qw>, C<readline>, C<readpipe>, C<ref>, C<sub*>, C<sysopen>, C<tie>,C<tied>, C<uc>, C<ucfirst>, C<untie>, C<use>* - C<sub> was a keyword in perl4, but in perl5 it is anoperator, which can be used in expressions.=item Functions obsoleted in perl5C<dbmclose>, C<dbmopen>=back=head2 PortabilityPerl was born in Unix and can therefore access all common Unixsystem calls. In non-Unix environments, the functionality of someUnix system calls may not be available, or details of the availablefunctionality may differ slightly. The Perl functions affectedby this are:C<-X>, C<binmode>, C<chmod>, C<chown>, C<chroot>, C<crypt>,C<dbmclose>, C<dbmopen>, C<dump>, C<endgrent>, C<endhostent>,C<endnetent>, C<endprotoent>, C<endpwent>, C<endservent>, C<exec>,C<fcntl>, C<flock>, C<fork>, C<getgrent>, C<getgrgid>, C<gethostent>,C<getlogin>, C<getnetbyaddr>, C<getnetbyname>, C<getnetent>,C<getppid>, C<getprgp>, C<getpriority>, C<getprotobynumber>,C<getprotoent>, C<getpwent>, C<getpwnam>, C<getpwuid>,C<getservbyport>, C<getservent>, C<getsockopt>, C<glob>, C<ioctl>,C<kill>, C<link>, C<lstat>, C<msgctl>, C<msgget>, C<msgrcv>,C<msgsnd>, C<open>, C<pipe>, C<readlink>, C<rename>, C<select>, C<semctl>,C<semget>, C<semop>, C<setgrent>, C<sethostent>, C<setnetent>,C<setpgrp>, C<setpriority>, C<setprotoent>, C<setpwent>,C<setservent>, C<setsockopt>, C<shmctl>, C<shmget>, C<shmread>,C<shmwrite>, C<socket>, C<socketpair>, C<stat>, C<symlink>, C<syscall>,C<sysopen>, C<system>, C<times>, C<truncate>, C<umask>, C<unlink>,C<utime>, C<wait>, C<waitpid>For more information about the portability of these functions, seeL<perlport> and other available platform-specific documentation.=head2 Alphabetical Listing of Perl Functions=over 8=item I<-X> FILEHANDLE=item I<-X> EXPR=item I<-X>A file test, where X is one of the letters listed below. This unaryoperator takes one argument, either a filename or a filehandle, andtests the associated file to see if something is true about it. If theargument is omitted, tests C<$_>, except for C<-t>, which tests STDIN.Unless otherwise documented, it returns C<1> for true and C<''> for false, orthe undefined value if the file doesn't exist. Despite the funnynames, precedence is the same as any other named unary operator, andthe argument may be parenthesized like any other unary operator. Theoperator may be any of:X<-r>X<-w>X<-x>X<-o>X<-R>X<-W>X<-X>X<-O>X<-e>X<-z>X<-s>X<-f>X<-d>X<-l>X<-p>X<-S>X<-b>X<-c>X<-t>X<-u>X<-g>X<-k>X<-T>X<-B>X<-M>X<-A>X<-C> -r File is readable by effective uid/gid. -w File is writable by effective uid/gid. -x File is executable by effective uid/gid. -o File is owned by effective uid. -R File is readable by real uid/gid. -W File is writable by real uid/gid. -X File is executable by real uid/gid. -O File is owned by real uid. -e File exists. -z File has zero size (is empty). -s File has nonzero size (returns size in bytes). -f File is a plain file. -d File is a directory. -l File is a symbolic link. -p File is a named pipe (FIFO), or Filehandle is a pipe. -S File is a socket. -b File is a block special file. -c File is a character special file. -t Filehandle is opened to a tty. -u File has setuid bit set. -g File has setgid bit set. -k File has sticky bit set. -T File is an ASCII text file. -B File is a "binary" file (opposite of -T). -M Age of file in days when script started. -A Same for access time. -C Same for inode change time.Example: while (<>) { chomp; next unless -f $_; # ignore specials #... }The interpretation of the file permission operators C<-r>, C<-R>,C<-w>, C<-W>, C<-x>, and C<-X> is by default based solely on the modeof the file and the uids and gids of the user. There may be otherreasons you can't actually read, write, or execute the file. Suchreasons may be for example network filesystem access controls, ACLs(access control lists), read-only filesystems, and unrecognizedexecutable formats.Also note that, for the superuser on the local filesystems, the C<-r>,C<-R>, C<-w>, and C<-W> tests always return 1, and C<-x> and C<-X> return 1if any execute bit is set in the mode. Scripts run by the superusermay thus need to do a stat() to determine the actual mode of the file,or temporarily set their effective uid to something else.If you are using ACLs, there is a pragma called C<filetest> that mayproduce more accurate results than the bare stat() mode bits.When under the C<use filetest 'access'> the above-mentioned filetestswill test whether the permission can (not) be granted using the
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?