Cover | Table of Contents | Colophon
http://www.cpan.org/) is the
place to go. The ongoing development and enhancement of Perl is very
much a cooperative effort, and CPAN is the place where the work of
many individuals comes together.
http://www.cpan.org/, but CPAN is also
mirrored on many other sites around the globe. This ensures that
anyone with an Internet connection can have reliable access to
CPAN's contents at any time. Since the structure of
all CPAN sites is the same, a user searching for the current version
of Perl can be sure that the stable.tar.gz file
is the same on every site.
ftp.perl.com
ftp.cs.colorado.edu
ftp.cise.ufl.edu
ftp.funet.fi
ftp.cs.ruu.nl
http://www.cpan.org/, but CPAN is also
mirrored on many other sites around the globe. This ensures that
anyone with an Internet connection can have reliable access to
CPAN's contents at any time. Since the structure of
all CPAN sites is the same, a user searching for the current version
of Perl can be sure that the stable.tar.gz file
is the same on every site.
ftp.perl.com
ftp.cs.colorado.edu
ftp.cise.ufl.edu
ftp.funet.fi
ftp.cs.ruu.nl
|
Item
|
Description
|
|---|---|
|
CPAN.html
|
CPAN info page; some general information about CPAN
|
|
ENDINGS
|
Description of the file extensions, such as
.tar, .gz, and
.zip
|
|
MIRRORED BY
|
A list of sites mirroring CPAN
|
|
MIRRORING.FROM
|
A list of sites mirrored by CPAN
|
|
README
|
A brief description of what you'll find on CPAN
|
|
README.html
|
An HTML-formatted version of the README file
|
|
RECENT
|
Recent additions to the CPAN site
|
|
RECENT.html
|
An HTML-formatted list of recent additions
|
|
ROADMAP |
@INC array and
prints the names of all modules it finds:
find `perl -e 'print "@INC"'` -name '*.pm' -print
by-authors Modules by author's registered CPAN name by-category Modules by subject matter (see below) by-module Modules by namespace (i.e., MIME)
02_Perl_Core_Modules 03_Development_Support 04_Operating_System_Interfaces 05_Networking_Devices_IPC 06_Data_Type_Utilities 07_Database_Interface 08_User_Interfaces 09_Language_Interfaces 10_File_Names_Systems_Locking 11_String_Lang_Text_Proc 12_Opt_Arg_Param_Proc 13_Internationalization_Locale 14_Security_and_Encryption 15_World_Wide_Web_HTML_HTTP_CGI 16_Server_and_Daemon_Utilities 17_Archiving_and_Compression 18_Images_Pixmaps_Bitmaps 19_Mail_and_Usenet_News 20_Control_Flow_Utilities 21_File_Handle_Input_Output 22_Microsoft_Windows_Modules 23_Miscellaneous_Modules 24_Commercial_Software_Interfaces 99_Not_In_Modulelist 99_Not_Yet_In_Modulelist
man perl or
perldoc perl to read the top-level page. This page
in turn directs you to more specific pages. Or, if you know which
page you want, you can go directly there by using:
% man perlvar
#!/usr/bin/perl
#! (hash-bang or shebang) line tells the shell to
look for the /usr/bin/perl program and pass the
rest of the file to that /usr/bin/perl for
execution. Sometimes, you'll see different pathnames
to the Perl executable, such as
/usr/local/bin/perl. You might see
perl5 or perl6 instead of
perl on sites that still depend on older
versions of Perl.
#!/usr/bin/perl.
#! line points to the location of the Perl
executable on your system. If you're on a Win32
platform, where the shebang path is used only to check for Perl
switches, you should make sure that you run
pl2bat.bat
on the
program so you can run it directly from the command line.
#! line, you can specify a short script directly
on the command line. Here are some of the possible ways to run Perl:
perl -e 'print "Hello, world\n"' # Unix perl -e "print \"Hello, world\n\"" # Win32 or Unix perl -e "print qq[Hello, world\n]" # Also Win32
perl testpgm
#! notation, specify the Perl command on the
#! line, make your script executable, and invoke
it from the shell (as described above).
echo "print 'Hello, world'" | perl - % perl print "Hello, world\n"; ^D
(open a "DOS" window) C:\> (edit your Perl program in your favorite editor) C:\> pl2bat yourprog.plx C:\> .\yourprog.bat (program output here)
#! line, it is
always examined for switches as the line is being parsed. Thus,
switches behave consistently regardless of how Perl was invoked.
-- switch that terminates
switch processing.
#!/usr/bin/perl -spi.bak
#!/usr/bin/perl -s -p -i.bak
|
Switch
|
Function
|
|---|---|
|
--
|
Terminates switch processing, even if the next argument starts with a
minus. It has no other effect.
|
|
-0[octnum]
|
Specifies the record separator (
$/) as an octal
number. If octnum is not present, the null
character is the separator. Other switches may precede or follow the
octal number.
|
|
-a
|
Turns on autosplit mode when used with -n or
-p. An implicit
split of the
@F array is inserted as the first command inside
the implicit while loop produced by
-n or -p. The default field
delimiter is whitespace; a different field delimiter may be specified
using -F.
|
|
-c
|
chdir has no
argument.
chdir has no argument and HOME is not
set.
C:\> set PATHEXT=%PATHEXT%;.PLX
C:\> myscript
use lib "/my/directory";
BEGIN { require 'perl5db.pl' }system function.
% perl -MO=CC,-ohi.c hi.pl hi.pl syntax OK % perl cc_harness -O2 -ohi hi.c # You may have to provide the full path of where cc_harness lives gcc -B/usr/ccs/bin/ -D_REENTRANT -DDEBUGGING -I/usr/local/include -I/usr/local/lib/perl5/sun4-solaris-thread/5.00466/CORE -O2 -ohi hi.c -L/usr/local/lib /usr/local/lib/perl5/sun4-solaris-thread/5.00466/CORE/libperl.a -lsocket -lnsl -lgdbm -ldl -lm -lposix4 -lpthread -lc -lcrypt % hi Hi there, world!
use strict pragma in your programs (see Chapter 8 for more information on pragmas and
strict in particular). This causes an error if you
do not explicitly declare your variables.
#). Everything
following a pound sign to the end of the line is interpreted as a
comment.
$). A scalar is either a number, a
string, or a reference. (A reference is a scalar that points to
another piece of data. References are discussed later in this
chapter.) If you provide a string in which a number is expected or
vice versa, Perl automatically converts the operand using fairly
intuitive rules.
@).
%).
12345
-54321
12345.67
6.02E23
0xffff
0377
4_294_967_296
0x for hex and 0 for octal work
only for literals. The automatic conversion of a string to a number
does not recognize these prefixes—you must do an explicit
conversion.
{ }. Compound statements
are built out of expressions and blocks. A conditional expression is
evaluated to determine whether a statement block will be executed.
Compound statements are defined in terms of blocks, not statements,
which means that braces are required.
SOMELABEL here:
SOMELABEL: {
...statements...
}next, last, and
redo to alter the flow of execution in your
programs.
if and
unless statements execute blocks of code depending
on whether a condition is met. These statements take the following
forms:
if (expression) {block} else {block} unless (expression) {block} else {block} if (expression1) {block} elsif (expression2) {block} ... elsif (lastexpression) {block} else {block}
while statement repeatedly executes a block as
long as its conditional expression is true. For example:
while (<INFILE>) {
chomp;
print OUTFILE, "$_\n";
}while is replaced by the word
until, the sense of the test is reversed. The
conditional is still tested before the first iteration, though.
$, @,
or %), such as $_. The
explicit, long-form names are the variables'
equivalents when you use the English module by including use
English; at the top of your program.
$_, which contains the default input and
pattern-searching string. For example:
foreach ('hickory','dickory','doc') {
print;
}$_ and is
used by default by print. Here are the places
where Perl will assume $_, even if you
don't specify it:
ord and int, as well as the all
file tests (-f, -d), except for
-t, which defaults to STDIN.
print and
unlink.
m//,
s///, and tr/// when used
without an =~ operator.
foreach loop if
no other variable is supplied.
grep and
map functions.
while test (i.e.,
<
filehandle
>).
Note that outside of a while test, this does not
happen.
$_
$ARG
$.$INPUT_LINE_NUMBER
$NR
|
Associativity
|
Operators
|
|---|---|
|
Left
|
Terms and list operators (leftward)
|
|
Left
|
-> (method call, dereference) |
|
Nonassociative
|
++ -- (autoincrement, autodecrement) |
|
Right
|
** (exponentiation) |
|
Right
|
! ~ \ and unary + and
- (logical not, bit-not, reference, unary plus,
unary minus)
|
|
Left
|
=~ !~ (matches, doesn't match) |
|
Left
|
* / % x (multiply, divide, modulus, string
replicate)
|
|
Left
|
+ - . (addition, subtraction, string concatenation) |
|
Left
|
<< >> (left bit-shift, right bit-shift) |
|
Nonassociative
|