(Ebook) Perl: The Complete Reference by Brown, Martin C. ISBN 9780072129502, 0072129506 2024 scribd download
(Ebook) Perl: The Complete Reference by Brown, Martin C. ISBN 9780072129502, 0072129506 2024 scribd download
https://ebooknice.com/product/perl-the-complete-reference-918684
ebooknice.com
https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374
ebooknice.com
(Ebook) XML Processing with Perl, Python, and PHP by Martin C. Brown
ISBN 0782140211
https://ebooknice.com/product/xml-processing-with-perl-python-and-
php-2143994
ebooknice.com
(Ebook) XML Processing with Perl, Python, and PHP by Martin C. Brown
ISBN 9780782140217, 0782140211
https://ebooknice.com/product/xml-processing-with-perl-python-and-
php-4433582
ebooknice.com
(Ebook) Matematik 5000+ Kurs 2c Lärobok by Lena Alfredsson, Hans
Heikne, Sanna Bodemyr ISBN 9789127456600, 9127456609
https://ebooknice.com/product/matematik-5000-kurs-2c-larobok-23848312
ebooknice.com
https://ebooknice.com/product/sat-ii-success-
math-1c-and-2c-2002-peterson-s-sat-ii-success-1722018
ebooknice.com
(Ebook) Master SAT II Math 1c and 2c 4th ed (Arco Master the SAT
Subject Test: Math Levels 1 & 2) by Arco ISBN 9780768923049,
0768923042
https://ebooknice.com/product/master-sat-ii-math-1c-and-2c-4th-ed-
arco-master-the-sat-subject-test-math-levels-1-2-2326094
ebooknice.com
https://ebooknice.com/product/cambridge-igcse-and-o-level-history-
workbook-2c-depth-study-the-united-states-1919-41-2nd-edition-53538044
ebooknice.com
https://ebooknice.com/product/c-the-complete-reference-7304404
ebooknice.com
TE
AM
FL
Y
Perl: The Complete Reference
Second Edition
This page intentionally left blank.
Perl:
The Complete Reference
Second Edition
Martin C. Brown
Osborne/McGraw-Hill
New York Chicago San Francisco
Lisbon London Madrid Mexico City
Milan New Delhi San Juan
Seoul Singapore Sydney Toronto
Copyright © 2001 by The McGraw-Hill Companies. All rights reserved. Manufactured in the United States of America. Except as per-
mitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by
any means, or stored in a database or retrieval system, without the prior written permission of the publisher.
0-07-219425-1
The material in this eBook also appears in the print version of this title: 0-07-212950-6.
All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trade-
marked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringe-
ment of the trademark. Where such designations appear in this book, they have been printed with initial caps.
McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate
training programs. For more information, please contact George Hoare, Special Sales, at [email protected] or (212)
904-4069.
TERMS OF USE
This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGraw-Hill”) and its licensors reserve all rights in and to the
work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and
retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works
based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill’s prior con-
sent. You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your
right to use the work may be terminated if you fail to comply with these terms.
THE WORK IS PROVIDED “AS IS”. McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES
AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE
WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR
OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill and its
licensors do not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will
be uninterrupted or error free. Neither McGraw-Hill nor its licensors shall be liable to you or anyone else for any inaccuracy, error
or omission, regardless of cause, in the work or for any damages resulting therefrom. McGraw-Hill has no responsibility for the con-
tent of any information accessed through the work. Under no circumstances shall McGraw-Hill and/or its licensors be liable for any
indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, even
if any of them has been advised of the possibility of such damages. This limitation of liability shall apply to any claim or cause what-
soever whether such claim or cause arises in contract, tort or otherwise.
DOI: 10.1036/0072194251
To Darcy and Leon, two little kittens
who do try to help daddy with the typing,
but usually just end up typing
“jjskdjjvoookko000000000000000000000”
About the Author
Martin C. Brown is the author of six Perl
books, including the first edition of Perl: The
Complete Reference, Perl Programmer’s Reference,
ActivePerl Developer’s Guide, and Debugging
Perl. In addition to Perl, he has worked in
Python, Java, Visual Basic, and other languages.
A programmer for 15 years, he is the former
IT director of a large advertising agency
dealing with blue chip clients such as Hewlett
Packard, Oracle, and Cable & Wireless.
Copyright 2001 The McGraw-Hill Companies, Inc. Click Here for Terms of Use.
Contents at a Glance
Part I Fundamentals
1 Perl Backgrounder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Perl Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3 Perl Parsing Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4 Variables and Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
5 Statements and Control Structures . . . . . . . . . . . . . . . . . . 109
6 Subroutines, Packages, and Modules . . . . . . . . . . . . . . . . 123
7 Working with Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
8 Data Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
9 Errors and Trapping Them . . . . . . . . . . . . . . . . . . . . . . . . . 269
vii
Copyright 2001 The McGraw-Hill Companies, Inc. Click Here for Terms of Use.
viii Perl: The Complete Reference
Part V Appendixes
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1153
Contents
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxiii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxv
Part I
Fundamentals
1 Perl Backgrounder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Versions and Naming Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Perl, perl or PeRl? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Life Before Perl 5.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Perl History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Main Perl Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Perl Is Free . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Perl Is Simple to Learn, Concise, and Easy to Read . . . . . . 7
Perl Is Fast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Perl Is Extensible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Perl Has Flexible Data Types . . . . . . . . . . . . . . . . . . . . . . . . . 8
Perl Is Object Oriented . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Perl Is Collaborative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Compiler or Interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
ix
Copyright 2001 The McGraw-Hill Companies, Inc. Click Here for Terms of Use.
x Perl: The Complete Reference
Perl Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Subroutines (Functions) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Where Next? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Team-Fly®
Contents xi
Part II
Programming with Perl
12 Networking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
Obtaining Network Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Hosts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
The Socket Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
Address Resolution and Conversion . . . . . . . . . . . . . . . . . . 369
Address Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Socket Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
Line Termination Constants . . . . . . . . . . . . . . . . . . . . . . . . . . 370
Socket Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Connecting to a Remote Socket . . . . . . . . . . . . . . . . . . . . . . . 371
Listening for Socket Connections . . . . . . . . . . . . . . . . . . . . . 374
Using IO::Socket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Client Side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Server Side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Using IO::Socket and IO::Select . . . . . . . . . . . . . . . . . . . . . . . 382
Getting Socket Addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Closing Sockets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
Socket Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
Data Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
Graham Barr’s libnet Bundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Gisle Aas’ LWP Bundle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Part III
Developing Applications
filetest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
integer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
less . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
lib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635
locale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636
open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636
ops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636
overload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
re . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
sigtrap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638
subs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639
vars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640
Part IV
Fine-Tuning Applications
Y
Traps for Programmers of Other Languages . . . . . . . . . . . . . . . . . . .
Differences from awk/gawk . . . . . . . . . . . . . . . . . . . . . . . . .
750
750
FL
C Traps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 752
sed Traps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 754
AM
Team-Fly®
Contents xxi
Part V
Appendixes
endpwent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897
endservent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897
eof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897
eval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 898
exec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899
exists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899
exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 900
exp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 900
fcntl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 901
fileno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 901
flock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 902
fork . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 903
format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 903
formline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 904
getc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 904
getgrent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 904
getgrgid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 905
getgrnam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906
gethostbyaddr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906
gethostbyname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 907
gethostent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 907
getlogin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 908
getnetbyaddr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 908
getnetbyname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 909
getnetent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 909
getpeername . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 910
getpgrp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 910
getppid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 911
getpriority . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 911
getprotobyname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 911
getprotobynumber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 912
getprotoent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 912
getpwent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 913
getpwnam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 914
getpwuid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 914
getservbyname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 915
getservbyport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 915
getservent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916
getsockname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916
getsockopt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 917
glob . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 918
gmtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 918
goto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 919
xxiv Perl: The Complete Reference
grep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 920
hex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 920
import . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 921
index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 921
int . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 922
ioctl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 922
join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 922
keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 923
kill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 923
last . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 925
lc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 925
lcfirst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 925
length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 926
link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 926
listen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 927
local . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 927
localtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 928
log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 928
lstat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 929
m// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 929
map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 929
mkdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 930
msgctl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 930
msgget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 931
msgrcv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 931
msgsnd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 932
my . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 932
next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 933
no . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 933
oct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 934
open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 934
opendir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 937
ord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 937
our . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 937
pack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 938
package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 940
pipe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 940
pop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 941
pos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 941
print . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 942
printf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 942
prototype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 945
push . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 945
Contents xxv
quotemeta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 946
rand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 946
read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 946
readdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 947
readline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 947
readlink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 948
readpipe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 948
recv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 949
redo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 949
ref . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 950
rename . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 951
require . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 951
reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 952
return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 952
reverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 953
rewinddir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 953
rindex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 953
rmdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 954
s/// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 954
scalar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 955
seek . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 955
seekdir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 956
select (filehandle) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 957
select (files) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 957
semctl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 958
semget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 958
semop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 958
send . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 959
setgrent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 960
sethostent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 960
setnetent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 960
setpgrp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961
setpriority . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961
setprotoent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 962
setpwent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 962
setservent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 962
setsockopt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 963
shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 964
shmctl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 964
shmget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 965
shmread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 966
shmwrite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 966
shutdown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 967
xxvi Perl: The Complete Reference
sin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 967
sleep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 968
socket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 968
socketpair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 969
sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 969
splice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 970
split . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 970
sprintf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 971
sqrt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 972
srand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 972
stat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 972
study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 974
sub . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 974
substr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 975
symlink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 975
syscall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 976
sysopen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 976
sysread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 978
sysseek . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 978
system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 979
syswrite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 980
tell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 980
telldir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 981
tie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 981
tied . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 982
time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 982
times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 982
tr/// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 983
truncate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 983
uc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 984
ucfirst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 984
umask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 984
undef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 985
unlink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 985
unpack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 986
unshift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 986
untie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 986
use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 987
utime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 988
values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 988
vec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 988
wait . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 989
waitpid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 989
Contents xxvii
wantarray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 990
warn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 991
write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 991
y/// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 992
Data::Dumper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1017
DB_File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1018
Devel::SelfStubber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1020
DirHandle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1020
DynaLoader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1021
English . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1021
Env . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1024
Errno . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1025
Exporter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1025
Unknown Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1026
Tag-Handling Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1026
Version Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1027
ExtUtils::Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1027
ExtUtils::Embed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1028
ExtUtils::Install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1029
ExtUtils::Installed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1029
ExtUtils::Liblist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1029
ExtUtils::MakeMaker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1030
ExtUtils::Manifest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1030
ExtUtils::Miniperl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1030
ExtUtils::Mkbootstrap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1030
ExtUtils::Mksymlists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1030
ExtUtils::MM_OS2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1030
ExtUtils::MM_Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1030
ExtUtils::MM_VMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1031
ExtUtils::MM_Win32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1031
ExtUtils::Packlist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1031
Fatal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1031
Fcntl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1031
FileCache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1032
FileHandle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1033
File::Basename . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1035
File::CheckTree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1036
File::Compare . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1037
File::Copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1037
File::DosGlob . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1038
File::Find . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1039
File::Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1040
File::Spec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1041
File::Spec::Mac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1042
File::Spec::OS2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1043
File::Spec::Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1043
File::Spec::VMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1045
Contents xxix
File::Spec::Win32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1046
FindBin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1046
GDBM_File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1047
Getopt::Long . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1048
Linkage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1049
Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1050
Callback Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1050
Return Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1051
Customizing GetOptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1051
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053
Getopt::Std . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053
I18N::Collate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1054
IO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1054
IO::File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1055
IO::Handle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1055
IO::Pipe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1058
IO::Seekable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1059
IO::Select . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1059
IO::Socket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1061
IO::Socket::INET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1063
IO::Socket::UNIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1065
IPC::Msg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1066
IPC::Open2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1067
IPC::Open3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1068
IPC::Semaphore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1068
IPC::SysV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1070
Math::BigFloat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1072
Math::BigInt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1073
Math::Complex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1075
Math::Trig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1076
Net::Ping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1077
NDBM_File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1078
O ........................................................ 1079
ODBM_File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1079
Opcode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1079
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1080
Opcode Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1082
Pod::Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1087
Pod::Html . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1087
Pod::Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1087
POSIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1089
Supported Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1089
Symbol Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1102
xxx Perl: The Complete Reference
Safe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1111
SDBM_File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1114
Search::Dict . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1114
SelectSaver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1114
SelfLoader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1115
Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1116
Socket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1116
Symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1118
Sys::Hostname . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1119
Sys::Syslog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1119
Term::Cap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1121
Term::Complete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1122
Term::ReadLine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1123
Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1124
Test::Harness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1127
Text::Abbrev . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1127
Text::ParseWords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1128
Text::Soundex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1129
Y
Text::Tabs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1130
FL
Text::Wrap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1131
Tie::Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1131
Tie::Handle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1132
AM
Tie::Hash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1132
Tie::RefHash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1133
Tie::Scalar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1133
TE
Tie::SubstrHash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1134
Time::Local . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1134
Time::gmtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1135
Time::localtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1136
Time::tm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1137
UNIVERSAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1137
User::grent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1138
User::pwent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1139
utf8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1139
C Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1141
Supplied Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1142
Unix Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1142
Windows Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 1143
Mac OS Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1143
Other Platforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1144
Books . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1144
Team-Fly®
Contents xxxi
Journals/Websites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1146
The Perl Journal (www.tpj.com) . . . . . . . . . . . . . . . . . . . . . . 1146
Internet.com (www.internet.com) . . . . . . . . . . . . . . . . . . . . . 1146
Server/Workstation Expert Magazine
(sun.expert.com) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1146
TechWeb (www.techweb.com) . . . . . . . . . . . . . . . . . . . . . . . 1146
Web Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1147
Mailing Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1148
General Mailing Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1149
Windows-Specific Mailing Lists . . . . . . . . . . . . . . . . . . . . . . 1149
Newsgroups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1150
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1153
This page intentionally left blank.
Acknowledgments
irst of all, I’d like to thank my wife. Two years ago, based on the offer for the first
F edition of Perl: The Complete Reference, she stood by me when I wanted to start
writing full time. Without her continued support, I wouldn’t have written the first
edition or the various other books that I’ve written since then, or been able to do this
second edition. Meanwhile, she still gives advice, listens to my rants when things aren’t
going well, and continues to be impressed when each book arrives.
Next, I’d like to thank all the people at Osborne who made this book possible. That
includes Wendy Rinaldi for offering me the opportunity, Rebekah Young for keeping
me in check, LeeAnn Pickrell and Betsy Manini for getting it through production, the
desktop compositors for laying out each chapter, and Andy Carroll and Bob Campbell
for doing the copy editing.
For technical input, thanks again to Mark Strivens, Ann-Marie Mallon, Huga van
der Sanden, Jon Nangle, and a myriad of others, including those people on Cix who
gave me ideas and input about topics and tricks that should be included in the book.
It’s not possible to write a Perl book without thanking Perl’s original author and the
current maintainers—that includes Larry Wall, Tom Christiansen, Randal L. Schwartz,
Sriram Srinivasan, Gurusamy Sarathay, and many many others. It continues to amaze
me how much you can cram into one language, and these people are the ones who do it.
If there’s anybody I’ve forgotten to acknowledge, I apologize unreservedly in
advance. I have done my best to check and verify all sources and contact all parties
involved, but it’s perfectly possible I made a mistake.
xxxiii
Copyright 2001 The McGraw-Hill Companies, Inc. Click Here for Terms of Use.
This page intentionally left blank.
Introduction
T possibly want to know about Perl. I’ve done my best to try and cover all the
different aspects, from the core of the language to the different functions, and
on into the different tasks and areas of the Perl language. I even cover how to debug
your software, write documentation, and then build and distribute your applications
or modules to the world at large. Along the way, we also look at some nonstandard
features and extensions, including better ways of networking, web programming, and
designing interfaces.
Throughout the entire book, you’ll find real-world examples and guides on how to
approach real problems using Perl—not just how to use the features of Perl. If all you
want is a quick reference guide to the different areas of Perl, then use the appendixes
at the end of the book and on the Web at www.osborne.com, which cover basic
components, functions, the Perl standard library, CPAN (Comprehensive Perl Archive
Network) extension library, a complete guide to errors and warnings, and a list of
resources for more information.
xxxv
Copyright 2001 The McGraw-Hill Companies, Inc. Click Here for Terms of Use.
xxxvi Perl: The Complete Reference
Chapter Breakdown
Each chapter in the book attempts to cover a different aspect of the solutions that Perl
is able to provide.
Chapter 1 looks at the background of Perl and the fundamental abilities that you
will need to use and understand in order to make the best use of Perl.
Chapter 2 examines the basic processes behind programming in Perl, from
installing Perl onto your machine (Unix, Windows, and Mac OS are covered), to
writing and executing your first script. We also look at some of the key terms that
you come across while reading the book and using Perl.
Chapter 3 covers all of the basic semantics and parsing rules behind the Perl
language, including an outline of how the execution process works, and all of the
different components that make up a Perl script.
Chapter 4 looks at the Perl variable types; Perl supports three basic types, the
scalar, the array and the hash (or associative array).
Chapter 5 details the statement and control structures that will control the flow
and execution of your program.
Chapter 6 starts off by covering the theories behind dissecting a program into
different components, from simple subroutines, right up to the more complex issues
of creating your own modules.
Chapter 7 covers the use of files, from the basics of printing information to the
screen to reading information from multiple files.
Chapter 8 details the processing behind data processing—by far the most useful
and popular use of Perl. We start by looking at basic ways of manipulating strings and
arrays before covering the Perl regular expression mechanism.
Chapter 9 looks at the basic mechanisms available for identifying and trapping errors
and bugs, and how to go about handling the situation without upsetting the user.
xxxviii Perl: The Complete Reference
Chapter 10 looks at the more complex data structures available in Perl—arrays and
hashes. We go beyond the normal uses of these structures and look at other ways they
can be employed to aid in the programming process. We also take the opportunity to
examine references, which provide a different way of accessing and using information
stored in variables, and this leads us on to nested data structures and object-oriented
programming. This final section also leads to tied data structures—a system whereby
information from an external source can be attached to an internal data structure.
Chapter 11 covers the different ways of finding out system information, such as
information about users and groups, time and how to manipulate time values, and
finally the environment and how it can affect the execution of your script.
Chapter 12 describes the processing required within Perl to support communication
over standard network sockets, such as those used for communication over the Internet.
Chapter 13 looks at the storage of information in external databases, both
homegrown and using systems such as DBM, Oracle, and ODBC sources.
Chapter 14 discusses the processes involved in interprocess communication, using
both standard filehandles and System V IPC functions. The chapter also describes the
methods available for creating, controlling, and communicating with external processes.
Chapter 15 details the more advanced methods of executing Perl scripts, from
supplying arguments to the command line, to executing scripts within scripts (using
eval), to multi-threaded execution.
Chapter 16 covers the basic processes behind getting and communicating
information back to your users through a structured interface on the command line
and back through the Perl reporting mechanism.
Chapter 17 takes a detailed look at user interfaces, especially at Perl/Tk—the Perl
interface to the Tk user interface development system.
Chapter 18 describes the environment available to you when you are writing
web scripts. This covers the physical environment of a script and also the ways of
communicating between the web server, the user’s browser, and a Perl script, otherwise
known as CGI. We then go on to look at smarter ways of handling the web-development
process and the specifics of web programming with Perl, including a useful checklist of
the security issues surrounding the web-programming process.
Chapter 19 looks at ways in which you can control the execution of your Perl script.
Perl uses a series of pragmas to improve the monitoring of potential problems in your
script, provide additional warnings and error messages, and change the way in which
different aspects of your scrip are interpreted.
Chapter 20 details the methods behind extending Perl through external C functions
and libraries or through embedding Perl into your existing applications.
Chapter 21 covers the essential process of debugging Perl scripts, both at a simple
level and at deeper levels within the Perl interpreter. We also look at how to debug
regular expressions and how to use the Perl profiler to determine which parts of your
Perl script need optimization.
Chapter 22 looks in detail at the Perl compiler. This supports several different
systems that take a Perl script and produce a number of different reports and output
formats. At a simple level, this includes a parsing tree that describes the real execution
Introduction xxxix
profile of your script, and at the other end of the scale, the compiler that supports the
creation of stand-alone Perl binaries.
Chapter 23 details the use and development of Perl documentation, both when
reading supplied documentation and writing your own.
Chapter 24 concentrates on ways in which you can write Perl programs that are
cross-platform compatible, even if you don’t know what the destination platform is.
We look at the basics of using Perl in different environments, the major differences and
things to watch out for, and also ways in which you can make a script more aware of
its surroundings.
Chapter 25 discusses the processes involved in releasing a Perl module to the Perl
community. In particular, it describes the MakeMaker utility for creating Perl Makefiles
that can compile and automatically install Perl extensions.
The appendixes at the back of the book provide a quick reference resource for Perl
functions (Appendix A) and the standard Perl library (Appendix B). Appendix C gives
a list of all of the different areas—books, websites, mailing lists, and newsgroups—that
can provide more information on how to use and program with Perl.
The appendixes on the Web (www.osborne.com) provide a reference to the core
Perl constructs (Web Appendix A), the extensions for Perl available from CPAN
(Web Appendix B), and a complete list and description of all the warnings and error
messages generated by the Perl interpreter (Web Appendix C).
Notes are formatted like this and include additional information about a particular
topic. You’ll also find similarly formatted “Cautions” and “Warnings,” which highlight
possible dangerous tools or tricks to watch out for when programming.
Y
FL
AM
TE
Team-Fly®
Part I
Fundamentals
Copyright 2001 The McGraw-Hill Companies, Inc. Click Here for Terms of Use.
This page intentionally left blank.
Chapter 1
Perl Backgrounder
Copyright 2001 The McGraw-Hill Companies, Inc. Click Here for Terms of Use.
4 Perl: The Complete Reference
erl is many different things to many different people. The most fundamental
On the 3d, 4th, and 5th of June I was very unwell, with premonitory
symptoms announcing a coming attack of the malignant fever of
Madagascar. It luckily happened that, during these days, nothing of any
interest occurred.
On the 6th of June Mr. Laborde gave a grand dinner in honor of Prince
Rakoto, in his garden-house, situate at the foot of the hill.
Although the dinner was announced for six o’clock, we were carried to
the house as early as three o’clock. On the way we passed a place in the
upper town on which nineteen heavy guns (eighteen-pounders) were
planted, the muzzles pointing toward the lower town, the suburbs, and the
valley. They were placed there by King Radama, who had received them as
a present from the English. They were not landed at Tamatavé, but at
Bombetok, on the eastern coast. The distance from this place to the capital
is greater than from Tamatavé, but the roads are better, and river
conveyance can be made available for several days’ journey.
On our arrival at Mr. Laborde’s garden-house, all kinds of efforts were
made to shorten the interval before dinner: several native sports were
exhibited, the most popular of which was a kind of “foot-boxing.” The
combatants kicked each other all over, and with such hearty good-will that I
expected every moment broken legs or ribs would be the result. This
delicate sport is in particular favor among the people in winter, as it
effectually warms those engaged in it. The coldest season here is between
the month of May till the end of July, when the thermometer often falls to
four, three, or even to one degree (Réaumur). Nevertheless, every thing
remains green; the trees do not lose their leaves, and the landscape looks as
pretty and blooming as in Europe in the middle of spring. The inhabitants of
Tananariva are fond of the summer heat, and as they have no means of
procuring wood, and of thus artificially supplying the want of animal heat,
they resort to the aforesaid pastime of foot-boxing.
The rich make their slaves bring wood from the distant forests to kindle
fires. In Mr. Laborde’s house, a coal fire was kept up in a great brazier from
early in the morning till late at night, but, of course, the door or the
windows remained always open. This piece of luxury costs a dollar per day
—a very high price compared with the cheapness of all other necessaries.
The foot-boxing was followed by dancing and gymnastic exercises; nor
was music wanting, for a band had been provided, which executed some
pieces skillfully enough. I was not so well pleased with the songs of a
number of native girls, who had been taught by a missionary residing with
Mr. Laborde. They knew a number of songs by heart, and did not scream in
such shrill fashion as those whom we had before heard; on the contrary,
their performance was tolerably correct; but it was a dreary entertainment,
and I was devoutly thankful when they came to the last bar.
A little before six o’clock came the prince, accompanied by his little son,
his beloved Mary, and a female friend of hers. Mary made even a less
favorable impression upon me than when I first saw her. The fault was in
her dress, for she was attired completely in the European style. Whatever
other people may say, the stiff, exaggerated fashions diffused by Paris over
the world do not charm me, even when worn by our own countrywomen,
and only look well on those whom nothing can disfigure; but where there is
a complete lack of natural beauty and grace, they become whimsical and
ridiculous, and particularly so in conjunction with clumsy figures and
monkey faces. Madame Mary may be a very good creature, and I should not
like to offend her in any way; but that did not prevent me from being
obliged to bite my lips till the blood almost came in the effort to avoid
laughing aloud at her appearance. Over half a dozen stiff-hooped petticoats
she wore a woolen dress with a number of great flounces, and great bows of
ribbon, the latter fastened, not in front, but at the back. She had thrown a
French shawl over her shoulders, and could never arrange it to her
satisfaction; and on the top of her head, woolly as a curled poodle’s, was
perched a quizzical little bonnet of reeds.
Her friend wore a muslin dress, and a cap of such antiquated form that,
sexagenarian as I am, I could never remember having seen one of similar
fashion; but afterward I remembered having seen a similar one on a portrait
of my grandmother, who lived about the middle of the last century. This
woman, who was of a more clumsy figure and had uglier features than
Mary, positively frightened me every time I looked at her; she always gave
me the idea of a cannibal chief in disguise.
The dinner-party was very cheerful. I had never seen Mr. Lambert in
such excellent spirits; as for the prince, he seems always in good-humor.
After dinner, Mr. Lambert and Mr. Laborde held a short political discussion
with the prince in another room. I was admitted to take part in this
conversation, and shall have to recur to it. The evening was unfortunately
somewhat spoiled for me by the singing chorus. The plentiful repast seemed
to have inspired the ladies with peculiar powers, for they screamed much
worse than before dinner, and, to increase the noise, clapped their hands as
an accompaniment. A few also performed the dreary dance of Madagascar
to the sound of the marovane, the only instrument yet invented by
Malagasey musical genius. It consists of a bamboo, as thick as a man’s arm,
and four feet long. Shreds of the bark are fastened all around it, supported
by little bridges of wood. The tone is very like that of a bad, worn-out
cithern.
As a conclusion, the guests themselves danced, and between the dances
Mr. Lambert gave us some very pretty songs.
About ten o’clock Mr. Laborde whispered to me that I should allege the
weakness that still remained from my late indisposition as a pretext for
breaking up the party. I replied that this was not my province, but that of
Prince Rakoto; but he urged me to do it, adding that he had a particular
reason for his request, which he would explain to me later; and,
accordingly, I broke up the party.
Favored by the brightest of moonlight, we marched up the hill toward
our dwellings to the sound of merry music.
Prince Rakoto and Mr. Lambert then called me into a side-chamber, and
the prince declared to me once more that the private contract between
himself and Mr. Lambert had been drawn up with his full concurrence, and
that he, the prince, had been grossly calumniated when he was represented
as intoxicated at the time of his signing it. He told me farther that Mr.
Lambert had come to Madagascar by his wish, and with the intention, in
conjunction with himself and a portion of the nobility and soldiers, to
remove Queen Ranavola from the throne, but without depriving her of her
freedom, her wealth, or the honors which were her due.
Mr. Lambert, on his part, informed me that we had dined in Mr.
Laborde’s garden-house because every thing could be more quietly
discussed there, and that I had been requested to break up the party that the
little feast might seem to have been given in my honor; finally, that we had
gone through the town with the noisy music as a sign that the object of our
meeting had been social amusement.
He then showed me in the house a complete little arsenal of sabres,
daggers, pistols, and guns, wherewith to arm the conspirators, and leather
shirts of mail for resisting lance-thrusts; and told me, in conclusion, that all
preparations had been made, and the time for action had almost come—in
fact, I might expect it every hour.
I confess that a strange feeling came over me when I found myself thus
suddenly involved in a political movement of grave importance, and at the
first moment a crowd of conflicting thoughts rushed through my brain. I
could not conceal from myself the fact that if the affair failed, my life
would be in the same danger as Mr. Lambert’s; for, in a country like
Madagascar, where every thing depends on the despotic will of the ruler, no
trouble is taken to determine the question of guilty or not guilty. I had come
to Tananariva in the company of one of the chief conspirators; I had also
been present at several meetings; more was not required to make me an
accomplice in the plot, and therefore just as worthy of punishment as the
active members themselves.
My friends in the Mauritius had certainly warned me previously against
undertaking the journey in Mr. Lambert’s company, and, from what had
been reported there, and likewise from some scattered words which Mr.
Lambert had let fall from time to time, I was able to form an idea of what
was going on; but my wish to obtain a knowledge of Madagascar was so
great that it stifled all fear. Now, indeed, there was no drawing back; and the
best I could do was to put a good face upon a bad matter, and trust in that
Providence which had already helped me in many and great dangers.
I gave Prince Rakoto and Mr. Lambert my most heartfelt wishes for the
success of their undertaking, and then retired to my room. It was already
past midnight. I went to bed, and, exhausted as I was, soon fell asleep; but
all night long I had disturbed dreams, and, among others, the following very
singular one: I dreamed that the plot had been discovered, and that the
queen had summoned Mr. Lambert and myself to the palace. We were
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com