.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.13 .\" .\" 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. | will give a .\" real vertical bar. \*(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-|\(bv .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\} .\" .\" 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. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" 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 .\" ======================================================================== .\" .TH PERL 1 "2003-09-02" "perl v5.8.1" "Perl Programmers Reference Guide" .SH NAME perl \- Practical Extraction and Report Language (实用摘录和汇报语言) .SH "总览 SYNOPSIS" \&\fBperl\fR [\ \fB\-sTuU\fR\ ] [\ \fB\-hv\fR\ ]\ [\ \fB\-V\fR[:\fIconfigvar\fR]\ ] [\ \fB\-cw\fR\ ]\ [\ \fB\-d\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\fR]\ ] [\ \fB\-I\fR\fIdir\fR\ ]\ [\ \fB\-m\fR[\fB\-\fR]\fImodule\fR\ ]\ [\ \fB\-M\fR[\fB\-\fR]\fI'module...'\fR\ ] [\ \fB\-P\fR\ ] [\ \fB\-S\fR\ ] [\ \fB\-x\fR[\fIdir\fR]\ ] [\ \fB\-i\fR[\fIextension\fR]\ ] [\ \fB\-e\fR\ \fI'command'\fR\ ]\ [\ \fB\-\-\fR\ ]\ [\ \fIprogramfile\fR\ ]\ [\ \fIargument\fR\ ]... .PP 如果你是 Perl 新手,还是从 perlintro 看起吧,那是为初学者准备的简单介绍,提供了一些背景知识,帮助你浏览 Perl 其余的大量文档 .PP 为方便阅读,Perl 手册分成了很多章 .Sh "概述 Overview" .Vb 3 \& perl Perl 概述 (本小节) \& perlintro Perl 介绍 (为新手准备) \& perltoc Perl 目录 (所有内容列表) .Ve .Sh "教程 Tutorials" .Vb 3 \& perlreftut Perl 引用 \& perldsc Perl 数据结构 \& perllol Perl 高级数据结构 .Ve .PP .Vb 2 \& perlrequick Perl 正则表达式快速入门 \& perlretut Perl 正则表达式 .Ve .PP .Vb 4 \& perlboot Perl OO 面向对象 入门 \& perltoot Perl OO 面向对象 教程 (第一部分) \& perltooc Perl OO 面向对象 教程 (第二部分) \& perlbot Perl OO 面向对象 窍门和例子 .Ve .PP .Vb 1 \& perlstyle Perl 程序风格 .Ve .PP .Vb 3 \& perlcheat Perl 投机取巧 \& perltrap Perl 大意者的陷阱 \& perldebtut Perl 调试 .Ve .PP .Vb 10 \& perlfaq Perl 常见问题 \& perlfaq1 有关 Perl 的一般问题 \& perlfaq2 获取/学习 Perl \& perlfaq3 编程工具 \& perlfaq4 数据操纵 \& perlfaq5 文件与文件格式 \& perlfaq6 正则表达式 \& perlfaq7 Perl 语言本身的问题 \& perlfaq8 与操作系统交互 \& perlfaq9 网络 .Ve .Sh "参考手册 Reference Manual" .Vb 21 \& perlsyn Perl 语法 \& perldata Perl 数据结构 \& perlop Perl 操作符及优先级 \& perlsub Perl 定义函数 \& perlfunc Perl 内置函数 \& perlopentut Perl open() 教程 \& perlpacktut Perl pack() 和 unpack() 教程 \& perlpod Perl POD 文档 \& perlpodspec Perl POD 文档格式规约 \& perlrun Perl 执行选项 \& perldiag Perl 诊断信息 \& perllexwarn Perl 警告 控制警告 \& perldebug Perl 调试 \& perlvar Perl 预定义变量 \& perlre Perl 正则表达式 其余的部分 \& perlreref Perl 正则表达式快速索引 \& perlref Perl 参考 其余的部分 \& perlform Perl 格式 \& perlobj Perl 对象 \& perltie Perl 用简单变量隐藏对象 \& perldbmfilter Perl DBM 层 .Ve .PP .Vb 3 \& perlipc Perl 进程间通信 \& perlfork Perl fork() 相关信息 \& perlnumber Perl 数字的语义 .Ve .PP .Vb 2 \& perlthrtut Perl 线程 \& perlothrtut 旧版 Perl 线程 .Ve .PP .Vb 5 \& perlport Perl 移植向导 \& perllocale Perl 语言环境支持 \& perluniintro Perl Unicode 介绍 \& perlunicode Perl Unicode 支持 \& perlebcdic 在 EBCDIC 平台上运行 Perl .Ve .PP .Vb 1 \& perlsec Perl 安全性 .Ve .PP .Vb 5 \& perlmod Perl modules: 它如何工作 \& perlmodlib Perl modules: 如何写和用它们 \& perlmodstyle Perl modules: 如何写好它 \& perlmodinstall Perl modules: 如何从 CPAN 安装它们 \& perlnewmod Perl modules: 准备释放出新模块 .Ve .PP .Vb 1 \& perlutil Perl 附带的工具 .Ve .PP .Vb 1 \& perlcompile Perl 编译套件介绍 .Ve .PP .Vb 1 \& perlfilter Perl 源码过滤 .Ve .Sh "内部以及 C 接口 Internals and C Language Interface" .Vb 7 \& perlembed 在 C/C++ 应用中内置 Perl 的独特方法 \& perldebguts Perl 调试要点和技巧 \& perlxstut Perl XS \& perlxs Perl XS 应用程序编程接口 \& perlclib 标准 C 库的内部实现 \& perlguts 为高级开发者准备的 Perl 内部函数 \& perlcall 从 C 转换为 Perl 调用 .Ve .PP .Vb 4 \& perlapi Perl API 列表 (自动生成) \& perlintern Perl 内部函数 (自动生成) \& perliol Perl 以\(lq层\(rq方式实现 IO 用到的 C API \& perlapio Perl 内部 IO 抽象接口 .Ve .PP .Vb 1 \& perlhack 修改 Perl .Ve .Sh "杂项 Miscellaneous" .Vb 2 \& perlbook Perl 书籍信息 \& perltodo Perl 的未来 .Ve .PP .Vb 1 \& perldoc 查看 Pod 格式的 Perl 文档 .Ve .PP .Vb 11 \& perlhist Perl 历史记录 \& perldelta Perl 上一版本以来的变动 \& perl58delta Perl 5.8.0 带来的变化 \& perl573delta Perl changes in version 5.7.3 \& perl572delta Perl changes in version 5.7.2 \& perl571delta Perl changes in version 5.7.1 \& perl570delta Perl changes in version 5.7.0 \& perl561delta Perl changes in version 5.6.1 \& perl56delta Perl changes in version 5.6 \& perl5005delta Perl changes in version 5.005 \& perl5004delta Perl changes in version 5.004 .Ve .PP .Vb 2 \& perlartistic Perl Artistic License \& perlgpl GNU General Public License .Ve .Sh "语言相关 Language-Specific" .Vb 4 \& perlcn Perl 简体中文支持 (原文是 EUC-CN 编码) \& perljp Perl 日本语支持 (原文是 EUC-JP 编码) \& perlko Perl 朝鲜语支持 (原文是 EUC-KR 编码) \& perltw Perl 繁体中文支持 (原文是 Big5 编码) .Ve .Sh "平台相关 Platform-Specific" .Vb 32 \& perlaix Perl notes for AIX \& perlamiga Perl notes for AmigaOS \& perlapollo Perl notes for Apollo DomainOS \& perlbeos Perl notes for BeOS \& perlbs2000 Perl notes for POSIX-BC BS2000 \& perlce Perl notes for WinCE \& perlcygwin Perl notes for Cygwin \& perldgux Perl notes for DG/UX \& perldos Perl notes for DOS \& perlepoc Perl notes for EPOC \& perlfreebsd Perl notes for FreeBSD \& perlhpux Perl notes for HP-UX \& perlhurd Perl notes for Hurd \& perlirix Perl notes for Irix \& perlmachten Perl notes for Power MachTen \& perlmacos Perl notes for Mac OS (Classic) \& perlmacosx Perl notes for Mac OS X \& perlmint Perl notes for MiNT \& perlmpeix Perl notes for MPE/iX \& perlnetware Perl notes for NetWare \& perlos2 Perl notes for OS/2 \& perlos390 Perl notes for OS/390 \& perlos400 Perl notes for OS/400 \& perlplan9 Perl notes for Plan 9 \& perlqnx Perl notes for QNX \& perlsolaris Perl notes for Solaris \& perltru64 Perl notes for Tru64 \& perluts Perl notes for UTS \& perlvmesa Perl notes for VM/ESA \& perlvms Perl notes for VMS \& perlvos Perl notes for Stratus VOS \& perlwin32 Perl notes for Windows .Ve .PP 默认情况下,上面列出的手册页安装在 \&\fI/usr/local/man/\fR 目录 .PP 还有大量有关 Perl 模块的文档。默认的 perl 配置会将它们安装到 \fI/usr/local/lib/perl5/man\fR 目录,(或者 Perl 库目录中的 \fIman\fR 子目录). 它们中的一部分是随 Perl 发布的标准文档, 另外你还可以从中找到第三方的文档 .PP 你可以用 \fIman\fR\|(1) 程序来查看 Perl 的文档,只要在配置文件中加入合适的路径, 或者将路径设置在 \s-1MANPATH\s0 环境变量中。要找出 perl 所有手册页的路径,只要运行 .PP .Vb 1 \& perl -V:man.dir .Ve .PP 如果路径有共同点,例如 \fI/usr/local/man/man1\fR 和 \fI/usr/local/man/man3\fR, 你只要将共同点 (\fI/usr/local/man\fR) 加入到 \fIman\fR\|(1) 的配置文件中,或是 \s-1MANPATH\s0 环境变量中。如果它们没有共同点,就必须全部添加 .PP 如果这样做没有效果,你也可以用附带的 \fIperldoc\fR 脚本来查看模块信息。也可以找一个 man 的替代程序 .PP 如果你的程序出了问题,又不知道该到哪里去找帮助,就先试一试 \fB\-w\fR 选项。它会精确地报告错误发生在哪一行 .SH "描述 DESCRIPTION" Perl 是一种特别为扫描复杂文本文件优化过的语言, 从中提取有用的信息,然后据此生成结果。 它也是系统管理任务中很好用的语言。它的目标是实用 (易用,高效,完整) 而不是 精致 (小,优雅,功能有限) .PP Perl 结合了 (在作者看来) C, \fBsed\fR, \fBawk\fR, 还有 \fBsh\fR 的优点,熟悉它们的人学起 Perl 毫无困难。 (语言学家还会从中发现一些 \fBcsh\fR, Pascal, 甚至 \&\s-1BASIC\-PLUS\s0 中的元素。) 表达式语法与 C 表达式语法紧密对应。与大多数 Unix 工具不同,Perl 不限制 你的数据的大小 \*(-- 只要你有足够的内存,Perl 可以把你的整个文件当作单一的字符串来享受。 递归的深度是无限的。 散列 (有时又叫做\(lq关联数组\(rq \&\*(L"associative arrays\*(R" ) 会按需生长,以避免性能下降。 Perl 使用精致的模式匹配技术来保证快速扫描大量数据。 尽管为扫描文本而优化,Perl 仍然可以处理二进制数据,也可以像使用散列一样使用 dbm 文件。 设置了 UID 的 Perl 脚本要比 C 程序安全,因为数据流跟踪机制可以堵上很多愚蠢的安全漏洞 .PP 如果你遇到了一般适于 \fBsed\fR 或 \fBawk\fR 或 \&\fBsh\fR 处理的问题,但是问题超出了工具的能力, 或者需要更快的处理,你又不想用 C 来写一大堆倒塌的程序,那么使用 Perl 吧。 另外,还有很多将 \fBsed\fR 和 \fBawk\fR 脚本转换为 Perl 脚本的翻译器 .PP 但是稍等,还有更多... .PP 自 1993 年开始 (参见 perlhist),Perl 5 进行了几乎完全的重写, 提供了以下的功能: .IP "\(bu" 4 模块性和可复用性 .Sp 详述在 perlmod, perlmodlib, 和 perlmodinstall 中 .IP "\(bu" 4 可内置可扩展 .Sp 详述在 perlembed, perlxstut, perlxs, perlcall, perlguts, 和 xsubpp 中 .IP "\(bu" 4 创建功能强大的数据类型 (同时包括多种 \s-1DBM\s0 实现) .Sp 详述在 perltie 和 AnyDBM_File 中 .IP "\(bu" 4 函数可重载,自动加载,原型化 .Sp 详述在 perlsub 中 .IP "\(bu" 4 复杂的数据结构嵌套还有匿名函数 .Sp 详述在 perlreftut, perlref, perldsc, 和 perllol 中 .IP "\(bu" 4 面向对象编程 .Sp 详述在 perlobj, perlboot, perltoot, perltooc, 和 perlbot 中 .IP "\(bu" 4 支持轻量级进程 (线程) .Sp 详述在 perlthrtut 和 threads 中 .IP "\(bu" 4 支持 Unicode,国际化和本地化 .Sp 详述在 perluniintro, perllocale 和 Locale::Maketext 中 .IP "\(bu" 4 变量作用域 .Sp 详述在 perlsub 中 .IP "\(bu" 4 正则表达式强化 .Sp 详述在 perlre 中,perlop 中有更多例子 .IP "\(bu" 4 强化的调试工具和交互的 Perl 环境,支持集成的编辑器 .Sp 详述在 perldebtut, perldebug 和 perldebguts 中 .IP "\(bu" 4 \&\s-1POSIX\s0 1003.1 兼容的库 .Sp 详述在 \s-1POSIX\s0 中 .PP Okay, 这些已经是绝对的绝对够用了 .SH "可用性 AVAILABILITY" Perl 在大部分操作系统上都可用,包含几乎所有类 Unix 的平台。参见 perlport 中的 \*(L"Supported Platforms\*(R" 段来查看平台列表 .SH "环境 ENVIRONMENT" 参见 perlrun .SH "作者 AUTHOR" Larry Wall , with the help of oodles of other folks. .PP 如果你使用 Perl 的成功案例对想在项目中应用 Perl 的人有用, 或者如果你只是想想表达你对 Larry 和 Perl 开发者的感激之情,请写信到 .SH "文件 FILES" .Vb 1 \& "@INC" locations of perl libraries .Ve .SH "参见 SEE ALSO" .Vb 2 \& a2p awk 到 perl 翻译器 \& s2p sed 到 perl 翻译器 .Ve .PP .Vb 3 \& http://www.perl.com/ Perl 官方主页 \& http://www.cpan.org/ the Comprehensive Perl Archive (Perl 文件中心) \& http://www.perl.org/ Perl Mongers (Perl 用户组) .Ve .SH "诊断 DIAGNOSTICS" \f(CW\*(C`use warnings\*(C'\fR 编译指示 (pragma) (还有 \fB\-w\fR 选项) 会产生 一些有用的诊断信息 .PP 参见 perldiag 来查看所有 Perl 诊断信息的含义。 \f(CW\*(C`use diagnostics\*(C'\fR 编译指示会自动将 Perl 简短的警告和错误消息 转换为长格式 .PP 编译错误将给出行号,还有要执行的下一个词或词的类型。 (在用 \fB\-e\fR 选项传给 Perl 的脚本中,每个 \&\fB\-e\fR 视为一行。) .PP 设置了 UID 的脚本有额外的约束,会产生格式化的错误信息,类似 \*(L"Insecure dependency\*(R"。参见 perlsec .PP 我们说过你一定要用 \fB\-w\fR 选项了吗? .SH "BUGS" \fB\-w\fR 选项不是必要的 .PP Perl 依赖于你的机器中操作的定义,类似于类型转换, \fIatof()\fR, 还有使用 \fIsprintf()\fR 来做浮点输出等操作 .PP 如果你的 stdio 在读写一个特殊流时需要一个 seek 或是 eof,Perl 也会需要它们。 (这种情况不会在 \fIsysread()\fR 和 \fIsyswrite()\fR 中发生。) .PP 所有内置数据类型都没有大小限制 (除了内存大小之外),但是还是有一些限制: 变量名不得长于 251 个字符。 诊断信息显示的行号以短整型数保存,因此行号最大值是 65535 (更大的行号一般会从头开始) .PP 可以将错误报告 (一定要包含完整的配置信息,使用 perl 源码树中的 myconfig 程序,或者用 \f(CW\*(C`perl \-V\*(C'\fR 命令得到) 寄给 perlbug@perl.org 。 如果你已经成功编译 perl, \fIutils/\fR 目录中的 \fBperlbug\fR 脚本可以用来邮寄错误报告 .PP Perl 真正意义是 Pathologically Eclectic Rubbish Lister, 但是 不要告诉任何人我说过它 .SH "注意 NOTES" Perl 的信条是 \*(L"There's more than one way to do it.\*(R" 至于探索有多少种办法,就是读者自己的事了 .PP 程序员应有的三种美德是 Laziness, Impatience, 还有 Hubris. 原因呢,请参见骆驼书 .SH "[中文版维护人]" .B bbbush .SH "[中文版最新更新]" .BR 2003.11.29 .SH "《中国linux论坛man手册翻译计划》:" .BI http://cmpp.linuxforum.net