summaryrefslogtreecommitdiff
path: root/pod
diff options
context:
space:
mode:
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>1997-04-23 00:00:00 +1200
committerChip Salzenberg <chip@atlantic.net>1997-04-23 00:00:00 +1200
commit46fc3d4c69a0adf236bfcba70daee7fd597cf30d (patch)
tree3b70f4a42d2ccd034756c9786032a1e531569e62 /pod
parent10a676f83f541430b63a3192b246bf6f86d3b189 (diff)
downloadperl-46fc3d4c69a0adf236bfcba70daee7fd597cf30d.tar.gz
[inseparable changes from match from perl-5.003_97g to perl-5.003_97h]
BUILD PROCESS Subject: Fix up Linux hints for tcsh, and Configure patch Date: Tue, 22 Apr 1997 11:02:27 -0400 (EDT) From: Andy Dougherty <doughera@lafcol.lafayette.edu> Files: Configure hints/linux.sh Msg-ID: Pine.SOL.3.95q.970422101051.2506C-100000@fractal.lafayette.e (applied based on p5p patch as commit 1eb1b1cb9647b817d039bb17afa3e74940b5ef92) Subject: There is no standard answer to 'Use suidperl?' From: Chip Salzenberg <chip@perl.com> Files: hints/bsdos.sh hints/freebsd.sh hints/linux.sh hints/machten_2.sh CORE LANGUAGE CHANGES Subject: Support PRINTF for tied handles Date: Sun, 20 Apr 1997 18:26:13 -0400 From: Doug MacEachern <dougm@opengroup.org> Files: pod/perldelta.pod pod/perltie.pod pp_sys.c t/op/misc.t Msg-ID: 199704202226.SAA08032@postman.osf.org (applied based on p5p patch as commit e7c5525577c16ee25e3521e86aca2b5105dba394) CORE PORTABILITY Subject: Fix bitwise shifts and pack('w') on Crays From: Chip Salzenberg <chip@perl.com> Files: pp.c DOCUMENTATION Subject: FAQ udpate (23-apr-97) Date: Wed, 23 Apr 1997 12:22:55 -0600 (MDT) From: Nathan Torkington <gnat@prometheus.frii.com> Files: pod/perlfaq*.pod private-msgid: 199704231822.MAA05074@prometheus.frii.com OTHER CORE CHANGES Subject: Mondo Cool patch for buffer safety and convenience From: Chip Salzenberg <chip@perl.com> Files: XSUB.h doop.c dump.c ext/DynaLoader/dl_dlopen.xs ext/DynaLoader/dl_hpux.xs ext/DynaLoader/dl_next.xs ext/DynaLoader/dlutils.c ext/ODBM_File/ODBM_File.xs global.sym gv.c interp.sym mg.c op.c perl.c perl.h pod/perlguts.pod pp.c pp_ctl.c pp_hot.c pp_sys.c proto.h regcomp.c regexec.c sv.c toke.c util.c Subject: Problems with glob Date: Sun, 20 Apr 1997 02:44:32 -0400 (EDT) From: Ilya Zakharevich <ilya@math.ohio-state.edu> Files: op.c Msg-ID: 1997Apr20.024432.1941365@hmivax.humgen.upenn.edu (applied based on p5p patch as commit a1230b335277820e65b8a9454ab751341204cf4f) Subject: Fix scalar leak in closures From: Chip Salzenberg <chip@perl.com> Files: op.c scope.c Subject: Refine error messages re: anon subs' prototypes From: Chip Salzenberg <chip@perl.com> Files: op.c Subject: Outermost scope is void, not scalar From: Chip Salzenberg <chip@perl.com> Files: pp_ctl.c
Diffstat (limited to 'pod')
-rw-r--r--pod/perldelta.pod31
-rw-r--r--pod/perlfaq.pod22
-rw-r--r--pod/perlfaq1.pod6
-rw-r--r--pod/perlfaq2.pod27
-rw-r--r--pod/perlfaq3.pod41
-rw-r--r--pod/perlfaq4.pod81
-rw-r--r--pod/perlfaq5.pod69
-rw-r--r--pod/perlfaq6.pod7
-rw-r--r--pod/perlfaq7.pod50
-rw-r--r--pod/perlfaq8.pod105
-rw-r--r--pod/perlfaq9.pod59
-rw-r--r--pod/perlguts.pod33
-rw-r--r--pod/perltie.pod20
-rw-r--r--pod/perltoc.pod81
14 files changed, 469 insertions, 163 deletions
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index 0613412bcd..70d2216e4d 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -490,6 +490,19 @@ the print function.
return print join( $, => map {uc} @_), $\;
}
+=item PRINTF this, LIST
+
+This method will be triggered every time the tied handle is printed to
+with the C<printf()> function.
+Beyond its self reference it also expects the format and list that was
+passed to the printf function.
+
+ sub PRINTF {
+ shift;
+ my $fmt = shift;
+ print sprintf($fmt, @_)."\n";
+ }
+
=item READ this LIST
This method will be called when the handle is read from via the C<read>
@@ -717,16 +730,16 @@ alphabetically:
FindBin.pm Find path of currently executing program
Class/Struct.pm Declare struct-like datatypes as Perl classes
- File/stat.pm By-name interface to Perl's built-in stat
- Net/hostent.pm By-name interface to Perl's built-in gethost*
- Net/netent.pm By-name interface to Perl's built-in getnet*
- Net/protoent.pm By-name interface to Perl's built-in getproto*
- Net/servent.pm By-name interface to Perl's built-in getserv*
- Time/gmtime.pm By-name interface to Perl's built-in gmtime
- Time/localtime.pm By-name interface to Perl's built-in localtime
+ File/stat.pm By-name interface to Perl's builtin stat
+ Net/hostent.pm By-name interface to Perl's builtin gethost*
+ Net/netent.pm By-name interface to Perl's builtin getnet*
+ Net/protoent.pm By-name interface to Perl's builtin getproto*
+ Net/servent.pm By-name interface to Perl's builtin getserv*
+ Time/gmtime.pm By-name interface to Perl's builtin gmtime
+ Time/localtime.pm By-name interface to Perl's builtin localtime
Time/tm.pm Internal object for Time::{gm,local}time
- User/grent.pm By-name interface to Perl's built-in getgr*
- User/pwent.pm By-name interface to Perl's built-in getpw*
+ User/grent.pm By-name interface to Perl's builtin getgr*
+ User/pwent.pm By-name interface to Perl's builtin getpw*
Tie/RefHash.pm Base class for tied hashes with references as keys
diff --git a/pod/perlfaq.pod b/pod/perlfaq.pod
index 99aeae953d..95a4a5c7f5 100644
--- a/pod/perlfaq.pod
+++ b/pod/perlfaq.pod
@@ -1,6 +1,6 @@
=head1 NAME
-perlfaq - frequently asked questions about Perl ($Date: 1997/03/25 18:20:48 $)
+perlfaq - frequently asked questions about Perl ($Date: 1997/04/23 18:11:06 $)
=head1 DESCRIPTION
@@ -64,8 +64,8 @@ at http://www.perl.com/perl/faq/ .
=head2 How to contribute to this document
You may mail corrections, additions, and suggestions to
-perlfaq-suggestions@perl.com. Mail sent to the old perlfaq alias will
-merely cause the FAQ to be sent to you.
+perlfaq-suggestions@perl.com . Mail sent to the old perlfaq alias
+will merely cause the FAQ to be sent to you.
=head2 What will happen if you mail your Perl programming problems to the authors
@@ -124,6 +124,20 @@ in respect of this information or its use.
=over 4
+=item 23/April/97
+
+Added http://www.oasis.leo.org/perl/ to L<perlfaq2>. Style fix to
+L<perlfaq3>. Added floating point precision, fixed complex number
+arithmetic, cross-references, caveat for Text::Wrap, alternative
+answer for initial capitalizing, fixed incorrect regexp, added example
+of Tie::IxHash to L<perlfaq4>. Added example of passing and storing
+filehandles, added commify to L<perlfaq5>. Restored variable suicide,
+and added mass commenting to L<perlfaq7>. Added Net::Telnet, fixed
+backticks, added reader/writer pair to telnet question, added FindBin,
+grouped module questions together in L<perlfaq8>. Expanded caveats
+for the simple URL extractor, gave LWP example, added CGI security
+question, expanded on the email address answer in L<perlfaq9>.
+
=item 25/March/97
Added more info to the binary distribution section of L<perlfaq2>.
@@ -131,7 +145,7 @@ Added Net::Telnet to L<perlfaq6>. Fixed typos in L<perlfaq8>. Added
mail sending example to L<perlfaq9>. Added Merlyn's columns to
L<perlfaq2>.
-=item 18/March/97
+=item 18/March/97
Added the DATE to the NAME section, indicating which sections have
changed.
diff --git a/pod/perlfaq1.pod b/pod/perlfaq1.pod
index 99d4b35bee..6463a98061 100644
--- a/pod/perlfaq1.pod
+++ b/pod/perlfaq1.pod
@@ -168,7 +168,7 @@ notice that perl is not itself written in Perl.
The new native-code compiler for Perl may reduce the limitations given
in the previous statement to some degree, but understand that Perl
remains fundamentally a dynamically typed language, and not a
-statically typed one. You certainly won't be chastised if you don't
+statically typed one. You certainly won't be chastized if you don't
trust nuclear-plant or brain-surgery monitoring code to it. And
Larry will sleep easier, too -- Wall Street programs not
withstanding. :-)
@@ -187,10 +187,10 @@ ok, while "awk and Perl" and "Python and perl" do not.
It doesn't matter.
In "standard terminology" a I<program> has been compiled to physical
-machine code once, and can then be run multiple times, whereas a
+machine code once, and can then be be run multiple times, whereas a
I<script> must be translated by a program each time it's used. Perl
programs, however, are usually neither strictly compiled nor strictly
-interpreted. They can be compiled to a bytecode form (something of a Perl
+interpreted. They can be compiled to a byte code form (something of a Perl
virtual machine) or to completely different languages, like C or assembly
language. You can't tell just by looking whether the source is destined
for a pure interpreter, a parse-tree interpreter, a byte code interpreter,
diff --git a/pod/perlfaq2.pod b/pod/perlfaq2.pod
index 95d542d566..8a954da64e 100644
--- a/pod/perlfaq2.pod
+++ b/pod/perlfaq2.pod
@@ -1,6 +1,6 @@
=head1 NAME
-perlfaq2 - Obtaining and Learning about Perl ($Revision: 1.15 $, $Date: 1997/03/25 18:15:48 $)
+perlfaq2 - Obtaining and Learning about Perl ($Revision: 1.16 $, $Date: 1997/04/23 18:04:09 $)
=head1 DESCRIPTION
@@ -62,7 +62,7 @@ eventually live on, and then type C<make install>. Most other
approaches are doomed to failure.
One simple way to check that things are in the right place is to print out
-the hardcoded @INC which perl is looking for.
+the hard-coded @INC which perl is looking for.
perl -e 'print join("\n",@INC)'
@@ -76,7 +76,7 @@ module/library directory?">.
=head2 I grabbed the sources and tried to compile but gdbm/dynamic loading/malloc/linking/... failed. How do I make it work?
Read the F<INSTALL> file, which is part of the source distribution.
-It describes in detail how to cope with most idiosyncrasies that the
+It describes in detail how to cope with most idiosyncracies that the
Configure script can't work around for any given system or
architecture.
@@ -84,7 +84,7 @@ architecture.
CPAN stands for Comprehensive Perl Archive Network, a huge archive
replicated on dozens of machines all over the world. CPAN contains
-source code, nonnative ports, documentation, scripts, and many
+source code, non-native ports, documentation, scripts, and many
third-party modules and extensions, designed for everything from
commercial database interfaces to keyboard/screen control to web
walking and CGI scripts. The master machine for CPAN is
@@ -191,7 +191,7 @@ before you buy!
What follows is a list of the books that the FAQ authors found personally
useful. Your mileage may (but, we hope, probably won't) vary.
-If you're already a hardcore systems programmer, then the Camel Book
+If you're already a hard-core systems programmer, then the Camel Book
just might suffice for you to learn Perl from. But if you're not,
check out the "Llama Book". It currently doesn't cover perl5, but the
2nd edition is nearly done and should be out by summer 97:
@@ -260,6 +260,9 @@ following list is I<not> the complete list of CPAN mirrors.
http://www.cs.ruu.nl/pub/PERL/CPAN/
ftp://ftp.cs.colorado.edu/pub/perl/CPAN/
+http:/www.oasis.leo.org/perl/ has, amongst other things, source to
+versions 1 through 5 of Perl.
+
=head2 What mailing lists are there for perl?
Most of the major modules (tk, CGI, libwww-perl) have their own
@@ -279,7 +282,7 @@ There is a mailing list for discussing Macintosh Perl. Contact
"mac-perl-request@iis.ee.ethz.ch".
Also see Matthias Neeracher's (the creator and maintainer of MacPerl)
-web page at http://www.iis.ee.ethz.ch/~neeri/macintosh/perl.html for
+webpage at http://www.iis.ee.ethz.ch/~neeri/macintosh/perl.html for
many links to interesting MacPerl sites, and the applications/MPW
tools, precompiled.
@@ -405,19 +408,19 @@ If you are reporting a bug in the perl interpreter or the modules
shipped with perl, use the perlbug program in the perl distribution or
email your report to perlbug@perl.com.
-If you are posting a bug with a nonstandard port (see the answer to
+If you are posting a bug with a non-standard port (see the answer to
"What platforms is Perl available for?"), a binary distribution, or a
-nonstandard module (such as Tk, CGI, etc), then please see the
+non-standard module (such as Tk, CGI, etc), then please see the
documentation that came with it to determine the correct place to post
bugs.
-Read the perlbug manpage (perl5.004 or later) for more information.
+Read the perlbug man page (perl5.004 or later) for more information.
=head2 What is perl.com? perl.org? The Perl Institute?
perl.org is the official vehicle for The Perl Institute. The motto of
TPI is "helping people help Perl help people" (or something like
-that). It's a nonprofit organization supporting development,
+that). It's a non-profit organization supporting development,
documentation, and dissemination of perl. Current directors of TPI
include Larry Wall, Tom Christiansen, and Randal Schwartz, whom you
may have heard of somewhere else around here.
@@ -425,8 +428,8 @@ may have heard of somewhere else around here.
The perl.com domain is Tom Christiansen's domain. He created it as a
public service long before perl.org came about. It's the original PBS
of the Perl world, a clearinghouse for information about all things
-Perlian, accepting no paid advertisements, glossy GIFs, or (gasp!)
-Java applets on its pages.
+Perlian, accepting no paid advertisements, glossy gifs, or (gasp!)
+java applets on its pages.
=head2 How do I learn about object-oriented Perl programming?
diff --git a/pod/perlfaq3.pod b/pod/perlfaq3.pod
index e6bfd3de73..7489e98a47 100644
--- a/pod/perlfaq3.pod
+++ b/pod/perlfaq3.pod
@@ -1,6 +1,6 @@
=head1 NAME
-perlfaq3 - Programming Tools ($Revision: 1.20 $, $Date: 1997/03/19 17:23:43 $)
+perlfaq3 - Programming Tools ($Revision: 1.21 $, $Date: 1997/04/23 18:04:23 $)
=head1 DESCRIPTION
@@ -11,7 +11,7 @@ and programming support.
Have you looked at CPAN (see L<perlfaq2>)? The chances are that
someone has already written a module that can solve your problem.
-Have you read the appropriate manpages? Here's a brief index:
+Have you read the appropriate man pages? Here's a brief index:
Objects perlref, perlmod, perlobj, perltie
Data Structures perlref, perllol, perldsc
@@ -22,12 +22,12 @@ Have you read the appropriate manpages? Here's a brief index:
Various http://www.perl.com/CPAN/doc/FMTEYEWTK/index.html
(not a man-page but still useful)
-L<perltoc> provides a crude table of contents for the perl manpage set.
+L<perltoc> provides a crude table of contents for the perl man page set.
=head2 How can I use Perl interactively?
The typical approach uses the Perl debugger, described in the
-perldebug(1) manpage, on an "empty" program, like this:
+perldebug(1) man page, on an "empty" program, like this:
perl -de 42
@@ -235,7 +235,7 @@ use in other parts of your program. (NB: my() variables also execute
about 10% faster than globals.) A global variable, of course, never
goes out of scope, so you can't get its space automatically reclaimed,
although undef()ing and/or delete()ing it will achieve the same effect.
-In general, memory allocation and deallocation isn't something you can
+In general, memory allocation and de-allocation isn't something you can
or should be worrying about much in Perl, but even this capability
(preallocation of data types) is in the works.
@@ -244,15 +244,15 @@ or should be worrying about much in Perl, but even this capability
Beyond the normal measures described to make general Perl programs
faster or smaller, a CGI program has additional issues. It may be run
several times per second. Given that each time it runs it will need
-to be recompiled and will often allocate a megabyte or more of system
+to be re-compiled and will often allocate a megabyte or more of system
memory, this can be a killer. Compiling into C B<isn't going to help
-you> because the process startup overhead is where the bottleneck is.
+you> because the process start-up overhead is where the bottleneck is.
There are at least two popular ways to avoid this overhead. One
solution involves running the Apache HTTP server (available from
http://www.apache.org/) with either of the mod_perl or mod_fastcgi
plugin modules. With mod_perl and the Apache::* modules (from CPAN),
-httpd will run with an embedded Perl interpreter which precompiles
+httpd will run with an embedded Perl interpreter which pre-compiles
your script and then executes it within the same address space without
forking. The Apache extension also gives Perl access to the internal
server API, so modules written in Perl can do just about anything a
@@ -287,7 +287,7 @@ instead of fixing them, is little security indeed.
You can try using encryption via source filters (Filter::* from CPAN).
But crackers might be able to decrypt it. You can try using the
byte code compiler and interpreter described below, but crackers might
-be able to decompile it. You can try using the native-code compiler
+be able to de-compile it. You can try using the native-code compiler
described below, but crackers might be able to disassemble it. These
pose varying degrees of difficulty to people wanting to get at your
code, but none can definitively conceal it (this is true of every
@@ -306,7 +306,7 @@ you want to be sure your licence's wording will stand up in court.
Malcolm Beattie has written a multifunction backend compiler,
available from CPAN, that can do both these things. It is as of
Feb-1997 in late alpha release, which means it's fun to play with if
-you're a programmer but not really for people looking for turnkey
+you're a programmer but not really for people looking for turn-key
solutions.
I<Please> understand that merely compiling into C does not in and of
@@ -334,14 +334,14 @@ you link your main perl binary with this, it will make it miniscule.
For example, on one author's system, /usr/bin/perl is only 11k in
size!
-=head2 How can I get '#!perl' to work on [MS-DOS,Windows NT,...]?
+=head2 How can I get '#!perl' to work on [MS-DOS,NT,...]?
For OS/2 just use
extproc perl -S -your_switches
as the first line in C<*.cmd> file (C<-S> due to a bug in cmd.exe's
-`extproc' handling). For MS-DOS one should first invent a corresponding
+`extproc' handling). For DOS one should first invent a corresponding
batch file, and codify it in C<ALTERNATIVE_SHEBANG> (see the
F<INSTALL> file in the source distribution for more information).
@@ -351,7 +351,7 @@ interpreter. If you install another port, or (eventually) build your
own Win95/NT Perl using WinGCC, then you'll have to modify the
Registry yourself.
-Macintosh perl scripts will have the appropriate Creator and
+Macintosh perl scripts will have the the appropriate Creator and
Type, so that double-clicking them will invoke the perl application.
I<IMPORTANT!>: Whatever you do, PLEASE don't get frustrated, and just
@@ -385,7 +385,7 @@ Yes. Read L<perlrun> for more information. Some examples follow.
Ok, the last one was actually an obfuscated perl entry. :-)
-=head2 Why don't perl one-liners work on my MS-DOS/Macintosh/VMS system?
+=head2 Why don't perl one-liners work on my DOS/Mac/VMS system?
The problem is usually that the command interpreters on those systems
have rather different ideas about quoting than the Unix shells under
@@ -398,10 +398,10 @@ For example:
# Unix
perl -e 'print "Hello world\n"'
- # MS-DOS, etc.
+ # DOS, etc.
perl -e "print \"Hello world\n\""
- # Macintosh
+ # Mac
print "Hello world\n"
(then Run "Myscript" or Shift-Command-R)
@@ -409,15 +409,15 @@ For example:
perl -e "print ""Hello world\n"""
The problem is that none of this is reliable: it depends on the command
-interpreter. Under Unix, the first two often work. Under MS-DOS, it's
+interpreter. Under Unix, the first two often work. Under DOS, it's
entirely possible neither works. If 4DOS was the command shell, I'd
probably have better luck like this:
perl -e "print <Ctrl-x>"Hello world\n<Ctrl-x>""
-Under the Macintosh, it depends which environment you are using. The MacPerl
+Under the Mac, it depends which environment you are using. The MacPerl
shell, or MPW, is much like Unix shells in its support for several
-quoting variants, except that it makes free use of the Macintosh's non-ASCII
+quoting variants, except that it makes free use of the Mac's non-ASCII
characters as control characters.
I'm afraid that there is no general solution to all of this. It is a
@@ -470,7 +470,7 @@ my C program, what am I doing wrong?
Download the ExtUtils::Embed kit from CPAN and run `make test'. If
the tests pass, read the pods again and again and again. If they
-fail, see L<perlbug> and send a bug report with the output of
+fail, see L<perlbug> and send a bugreport with the output of
C<make test TEST_VERBOSE=1> along with C<perl -V>.
=head2 When I tried to run my script, I got this message. What does it
@@ -501,3 +501,4 @@ information, see L<ExtUtils::MakeMaker>.
Copyright (c) 1997 Tom Christiansen and Nathan Torkington.
All rights reserved. See L<perlfaq> for distribution information.
+
diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod
index d3a7e8ccb9..7c57d58d7d 100644
--- a/pod/perlfaq4.pod
+++ b/pod/perlfaq4.pod
@@ -1,6 +1,6 @@
=head1 NAME
-perlfaq4 - Data Manipulation ($Revision: 1.17 $, $Date: 1997/03/25 18:16:24 $)
+perlfaq4 - Data Manipulation ($Revision: 1.18 $, $Date: 1997/04/23 18:04:37 $)
=head1 DESCRIPTION
@@ -10,6 +10,34 @@ data issues.
=head1 Data: Numbers
+=head2 Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?
+
+Internally, your computer represents floating-point numbers in binary.
+Floating-point numbers read in from a file, or appearing as literals
+in your program, are converted from their decimal floating-point
+representation (eg, 19.95) to the internal binary representation.
+
+However, 19.95 can't be precisely represented as a binary
+floating-point number, just like 1/3 can't be exactly represented as a
+decimal floating-point number. The computer's binary representation
+of 19.95, therefore, isn't exactly 19.95.
+
+When a floating-point number gets printed, the binary floating-point
+representation is converted back to decimal. These decimal numbers
+are displayed in either the format you specify with printf(), or the
+current output format for numbers (see L<perlvar/"$#"> if you use
+print. C<$#> has a different default value in Perl5 than it did in
+Perl4. Changing C<$#> yourself is deprecated.
+
+This affects B<all> computer languages that represent decimal
+floating-point numbers in binary, not just Perl. Perl provides
+arbitrary-precision decimal numbers with the Math::BigFloat module
+(part of the standard Perl distribution), but mathematical operations
+are consequently slower.
+
+To get rid of the superfluous digits, just use a format (eg,
+C<printf("%.2f", 19.95)>) to get the required precision.
+
=head2 Why isn't my octal data interpreted correctly?
Perl only understands octal and hex numbers as such when they occur
@@ -36,10 +64,12 @@ The POSIX module (part of the standard perl distribution) implements
ceil(), floor(), and a number of other mathematical and trigonometric
functions.
-The Math::Complex module (part of the standard perl distribution)
-defines a number of mathematical functions that can also work on real
-numbers. It's not as efficient as the POSIX library, but the POSIX
-library can't work with complex numbers.
+In 5.000 to 5.003 Perls, trigonometry was done in the Math::Complex
+module. With 5.004, the Math::Trig module (part of the standard perl
+distribution) implements the trigonometric functions. Internally it
+uses the Math::Complex module and some functions can break out from
+the real axis into the complex plane, for example the inverse sine of
+2.
Rounding in financial applications can have serious implications, and
the rounding method used should be specified precisely. In these
@@ -199,6 +229,9 @@ arbitrary expressions:
print "That yields ${\($n + 5)} widgets\n";
+See also "How can I expand variables in text strings?" in this section
+of the FAQ.
+
=head2 How do I find matching/nesting anything?
This isn't something that can be tackled in one regular expression, no
@@ -234,6 +267,9 @@ Use Text::Wrap (part of the standard perl distribution):
use Text::Wrap;
print wrap("\t", ' ', @paragraphs);
+The paragraphs you give to Text::Wrap may not contain embedded
+newlines. Text::Wrap doesn't justify the lines (flush-right).
+
=head2 How can I access/change the first N letters of a string?
There are many ways. If you just want to grab a copy, use
@@ -271,7 +307,7 @@ C<tr///> function like so:
$string = "ThisXlineXhasXsomeXx'sXinXit":
$count = ($string =~ tr/X//);
- print "There are $count X characters in the string";
+ print "There are $count X charcters in the string";
This is fine if you are just looking for a single character. However,
if you are trying to count multiple character substrings within a
@@ -289,6 +325,18 @@ To make the first letter of each word upper case:
$line =~ s/\b(\w)/\U$1/g;
+This has the strange effect of turning "C<don't do it>" into "C<Don'T
+Do It>". Sometimes you might want this, instead (Suggested by Brian
+Foy E<lt>comdog@computerdog.comE<gt>):
+
+ $string =~ s/ (
+ (^\w) #at the beginning of the line
+ | # or
+ (\s\w) #preceded by whitespace
+ )
+ /\U$1/xg;
+ $string =~ /([\w']+)/\u\L$1/g;
+
To make the whole line upper case:
$line = uc($line);
@@ -321,6 +369,11 @@ suggests (assuming your string is contained in $text):
}gx;
push(@new, undef) if substr($text,-1,1) eq ',';
+If you want to represent quotation marks inside a
+quotation-mark-delimited field, escape them with backslashes (eg,
+C<"like \"this\""). Unescaping them is a task addressed earlier in
+this section.
+
Alternatively, the Text::ParseWords module (part of the standard perl
distribution) lets you say:
@@ -368,6 +421,9 @@ substitution:
Which is bizarre enough that you'll probably actually need an EEG
afterwards. :-)
+See also "How do I expand function calls in a string?" in this section
+of the FAQ.
+
=head2 What's wrong with always quoting "$vars"?
The problem is that those double-quotes force stringification,
@@ -668,7 +724,7 @@ that's come to be known as the Schwartzian Transform:
@sorted = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
- map { [ $_, uc((/\d+\s*(\S+) )[0] ] } @data;
+ map { [ $_, uc((/\d+\s*(\S+)/ )[0] ] } @data;
If you need to sort on several fields, the following paradigm is useful.
@@ -900,7 +956,7 @@ they end up doing is not what they do with ordinary hashes.
Using C<keys %hash> in a scalar context returns the number of keys in
the hash I<and> resets the iterator associated with the hash. You may
need to do this if you use C<last> to exit a loop early so that when you
-reenter it, the hash iterator has been reset.
+re-enter it, the hash iterator has been reset.
=head2 How can I get the unique keys from two hashes?
@@ -938,6 +994,14 @@ it on top of either DB_File or GDBM_File.
Use the Tie::IxHash from CPAN.
+ use Tie::IxHash;
+ tie(%myhash, Tie::IxHash);
+ for ($i=0; $i<20; $i++) {
+ $myhash{$i} = 2*$i;
+ }
+ @keys = keys %myhash;
+ # @keys = (0,1,2,3,...)
+
=head2 Why does passing a subroutine an undefined element in a hash create it?
If you say something like:
@@ -1035,3 +1099,4 @@ Get the Business::CreditCard module from CPAN.
Copyright (c) 1997 Tom Christiansen and Nathan Torkington.
All rights reserved. See L<perlfaq> for distribution information.
+
diff --git a/pod/perlfaq5.pod b/pod/perlfaq5.pod
index 1c694f0347..898864b51a 100644
--- a/pod/perlfaq5.pod
+++ b/pod/perlfaq5.pod
@@ -1,6 +1,6 @@
=head1 NAME
-perlfaq5 - Files and Formats ($Revision: 1.20 $, $Date: 1997/03/19 17:24:51 $)
+perlfaq5 - Files and Formats ($Revision: 1.21 $, $Date: 1997/04/23 18:05:19 $)
=head1 DESCRIPTION
@@ -106,7 +106,7 @@ the changes you want, then copy that over the original.
rename($new, $old) or die "can't rename $new to $old: $!";
Perl can do this sort of thing for you automatically with the C<-i>
-command line switch or the closely-related C<$^I> variable (see
+command-line switch or the closely-related C<$^I> variable (see
L<perlrun> for more details). Note that
C<-i> may require a suffix on some non-Unix systems; see the
platform-specific documentation that came with your port.
@@ -231,6 +231,36 @@ Internally, Perl believes filehandles to be of class IO::Handle. You
may use that module directly if you'd like (see L<IO::Handle>), or
one of its more specific derived classes.
+Once you have IO::File or FileHandle objects, you can pass them
+between subroutines or store them in hashes as you would any other
+scalar values:
+
+ use FileHandle;
+
+ # Storing filehandles in a hash and array
+ foreach $filename (@names) {
+ my $fh = new FileHandle($filename) or die;
+ $file{$filename} = $fh;
+ push(@files, $fh);
+ }
+
+ # Using the filehandles in the array
+ foreach $file (@files) {
+ print $file "Testing\n";
+ }
+
+ # You have to do the { } ugliness when you're specifying the
+ # filehandle by anything other than a simple scalar variable.
+ print { $files[2] } "Testing\n";
+
+ # Passing filehandles to subroutines
+ sub debug {
+ my $filehandle = shift;
+ printf $filehandle "DEBUG: ", @_;
+ }
+
+ debug($fh, "Testing\n");
+
=head2 How can I set up a footer format to be used with write()?
There's no builtin way to do this, but L<perlform> has a couple of
@@ -262,6 +292,18 @@ You can't just:
because you have to put the comma in and then recalculate your
position.
+Alternatively, this commifies all numbers in a line regardless of
+whether they have decimal portions, are preceded by + or -, or
+whatever:
+
+ # from Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
+ sub commify {
+ my $input = shift;
+ $input = reverse $input;
+ $input =~ s<(\d\d\d)(?=\d)(?!\d*\.)><$1,>g;
+ return reverse $input;
+ }
+
=head2 How can I translate tildes (~) in a filename?
Use the E<lt>E<gt> (glob()) operator, documented in L<perlfunc>. This
@@ -406,13 +448,13 @@ atomic test-and-set instruction. In theory, this "ought" to work:
except that lamentably, file creation (and deletion) is not atomic
over NFS, so this won't work (at least, not every time) over the net.
-Various schemes involving link() have been suggested, but these tend
-to involve busy-wait, which is also subdesirable.
+Various schemes involving involving link() have been suggested, but
+these tend to involve busy-wait, which is also subdesirable.
=head2 I still don't get locking. I just want to increment the number
in the file. How can I do this?
-Didn't anyone ever tell you web page hit counters were useless?
+Didn't anyone ever tell you web-page hit counters were useless?
Anyway, this is what to do:
@@ -426,7 +468,7 @@ Anyway, this is what to do:
# DO NOT UNLOCK THIS UNTIL YOU CLOSE
close FH or die "can't close numfile: $!";
-Here's a much better web page hit counter:
+Here's a much better web-page hit counter:
$hits = int( (time() - 850_000_000) / rand(1_000) );
@@ -455,14 +497,14 @@ like this:
Locking and error checking are left as an exercise for the reader.
Don't forget them, or you'll be quite sorry.
-Don't forget to set binmode() under MS-DOS-like platforms when operating
+Don't forget to set binmode() under DOS-like platforms when operating
on files that have anything other than straight text in them. See the
docs on open() and on binmode() for more details.
=head2 How do I get a file's timestamp in perl?
If you want to retrieve the time at which the file was last read,
-written, or had its metadata (owner, etc) changed, you use the B<-M>,
+written, or had its meta-data (owner, etc) changed, you use the B<-M>,
B<-A>, or B<-C> filetest operations as documented in L<perlfunc>. These
retrieve the age of the file (measured against the start-time of your
program) in days as a floating point number. To retrieve the "raw"
@@ -602,7 +644,7 @@ The Term::ReadKey module from CPAN may be easier to use:
printf "\nYou said %s, char number %03d\n",
$key, ord $key;
-For MS-DOS systems, Dan Carson <dbc@tc.fluke.COM> reports the following:
+For DOS systems, Dan Carson <dbc@tc.fluke.COM> reports the following:
To put the PC in "raw" mode, use ioctl with some magic numbers gleaned
from msdos.c (Perl source file) and Ralf Brown's interrupt list (comes
@@ -737,17 +779,17 @@ to, you may be able to do this:
$rc = syscall(&SYS_close, $fd + 0); # must force numeric
die "can't sysclose $fd: $!" unless $rc == -1;
-=head2 Why can't I use "C:\temp\foo" in MS-DOS paths? What doesn't `C:\temp\foo.exe` work?
+=head2 Why can't I use "C:\temp\foo" in DOS paths? What doesn't `C:\temp\foo.exe` work?
Whoops! You just put a tab and a formfeed into that filename!
Remember that within double quoted strings ("like\this"), the
backslash is an escape character. The full list of these is in
L<perlop/Quote and Quote-like Operators>. Unsurprisingly, you don't
have a file called "c:(tab)emp(formfeed)oo" or
-"c:(tab)emp(formfeed)oo.exe" on your MS-DOS filesystem.
+"c:(tab)emp(formfeed)oo.exe" on your DOS filesystem.
Either single-quote your strings, or (preferably) use forward slashes.
-Since all MS-DOS and Windows versions since something like MS-DOS 2.0 or so
+Since all DOS and Windows versions since something like MS-DOS 2.0 or so
have treated C</> and C<\> the same in a path, you might as well use the
one that doesn't clash with Perl -- or the POSIX shell, ANSI C and C++,
awk, Tcl, Java, or Python, just to mention a few.
@@ -755,7 +797,7 @@ awk, Tcl, Java, or Python, just to mention a few.
=head2 Why doesn't glob("*.*") get all the files?
Because even on non-Unix ports, Perl's glob function follows standard
-Unix globbing semantics. You'll need C<glob("*")> to get all (nonhidden)
+Unix globbing semantics. You'll need C<glob("*")> to get all (non-hidden)
files.
=head2 Why does Perl let me delete read-only files? Why does C<-i> clobber protected files? Isn't this a bug in Perl?
@@ -786,3 +828,4 @@ file in.
Copyright (c) 1997 Tom Christiansen and Nathan Torkington.
All rights reserved. See L<perlfaq> for distribution information.
+
diff --git a/pod/perlfaq6.pod b/pod/perlfaq6.pod
index 1cec15c669..1af7948339 100644
--- a/pod/perlfaq6.pod
+++ b/pod/perlfaq6.pod
@@ -240,7 +240,7 @@ Without the \Q, the regexp would also spuriously match "di".
=head2 What is C</o> really for?
-Using a variable in a regular expression match forces a reevaluation
+Using a variable in a regular expression match forces a re-evaluation
(and perhaps recompilation) each time through. The C</o> modifier
locks in the regexp the first time it's used. This always happens in a
constant regular expression, and in fact, the pattern was compiled
@@ -520,7 +520,7 @@ But then you lose the vertical alignment of the regular expressions.
While it's true that Perl's regular expressions resemble the DFAs
(deterministic finite automata) of the egrep(1) program, they are in
-fact implemented as NFAs (nondeterministic finite automata) to allow
+fact implemented as NFAs (non-deterministic finite automata) to allow
backtracking and backreferencing. And they aren't POSIX-style either,
because those guarantee worst-case behavior for all cases. (It seems
that some people prefer guarantees of consistency, even when what's
@@ -590,7 +590,7 @@ katakana (in Shift-JIS or EUC encoding) is available from CPAN as
=for Tom make it so
-There are many double (and multi) byte encodings commonly used these
+There are many double- (and multi-) byte encodings commonly used these
days. Some versions of these have 1-, 2-, 3-, and 4-byte characters,
all mixed.
@@ -598,3 +598,4 @@ all mixed.
Copyright (c) 1997 Tom Christiansen and Nathan Torkington.
All rights reserved. See L<perlfaq> for distribution information.
+
diff --git a/pod/perlfaq7.pod b/pod/perlfaq7.pod
index a1d60f84d5..908fc14e7c 100644
--- a/pod/perlfaq7.pod
+++ b/pod/perlfaq7.pod
@@ -298,6 +298,26 @@ E<lt>STDINE<gt>'>, there would have been no way for the hypothetical
timeout() function to access the lexical variable $line back in its
caller's scope.
+=head2 What is variable suicide and how can I prevent it?
+
+Variable suicide is when you (temporarily or permanently) lose the
+value of a variable. It is caused by scoping through my() and local()
+interacting with either closures or aliased foreach() interator
+variables and subroutine arguments. It used to be easy to
+inadvertently lose a variable's value this way, but now it's much
+harder. Take this code:
+
+ my $f = "foo";
+ sub T {
+ while ($i++ < 3) { my $f = $f; $f .= "bar"; print $f, "\n" }
+ }
+ T;
+ print "Finally $f\n";
+
+The $f that has "bar" added to it three times should be a new C<$f>
+(C<my $f> should create a new local variable each time through the
+loop). It isn't, however. This is a bug, and will be fixed.
+
=head2 How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regexp}?
With the exception of regexps, you need to pass references to these
@@ -339,9 +359,9 @@ IO::File modules, both part of the standard Perl distribution.
To pass regexps around, you'll need to either use one of the highly
experimental regular expression modules from CPAN (Nick Ing-Simmons's
-Regexp or Ilya Zakharevich's Devel::Regexp), pass around strings and
-use an exception-trapping eval, or else be very, very clever. Here's
-an example of how to pass in a string to be regexp compared:
+Regexp or Ilya Zakharevich's Devel::Regexp), pass around strings
+and use an exception-trapping eval, or else be be very, very clever.
+Here's an example of how to pass in a string to be regexp compared:
sub compare($$) {
my ($val1, $regexp) = @_;
@@ -539,7 +559,7 @@ Why do you want to do that? :-)
If you want to override a predefined function, such as open(),
then you'll have to import the new definition from a different
module. See L<perlsub/"Overriding Builtin Functions">. There's
-also an example in L<perltoot/"Class::Struct">.
+also an example in L<perltoot/"Class::Template">.
If you want to overload a Perl operator, such as C<+> or C<**>,
then you'll want to use the C<use overload> pragma, documented
@@ -576,7 +596,7 @@ how best to do this, so he left it out, even though it's been on the
wish list since perl1.
Here's a simple example of a switch based on pattern matching. We'll
-do a multiway conditional based on the type of reference stored in
+do a multi-way conditional based on the type of reference stored in
$whatchamacallit:
SWITCH:
@@ -669,6 +689,26 @@ not necessarily the same as the one in which you were compiled):
warn "called me from a $class object";
}
+=head2 How can I comment out a large block of perl code?
+
+Use embedded POD to discard it:
+
+ # program is here
+
+ =for nobody
+ This paragraph is commented out
+
+ # program continues
+
+ =begin comment text
+
+ all of this stuff
+
+ here will be ignored
+ by everyone
+
+ =end comment text
+
=head1 AUTHOR AND COPYRIGHT
Copyright (c) 1997 Tom Christiansen and Nathan Torkington.
diff --git a/pod/perlfaq8.pod b/pod/perlfaq8.pod
index 831b1b41e7..f559d6a2f2 100644
--- a/pod/perlfaq8.pod
+++ b/pod/perlfaq8.pod
@@ -1,6 +1,6 @@
=head1 NAME
-perlfaq8 - System Interaction ($Revision: 1.17 $, $Date: 1997/03/25 18:17:12 $)
+perlfaq8 - System Interaction ($Revision: 1.20 $, $Date: 1997/04/23 18:11:50 $)
=head1 DESCRIPTION
@@ -10,7 +10,7 @@ control over the user-interface (keyboard, screen and pointing
devices), and most anything else not related to data manipulation.
Read the FAQs and documentation specific to the port of perl to your
-operating system (eg, L<perlvms>, F<REAMDE.os2>, ...). These should
+operating system (eg, L<perlvms>, L<perlplan9>, ...). These should
contain more detailed information on the vagaries of your perl.
=head2 How do I find out which operating system I'm running under?
@@ -104,7 +104,7 @@ give the numeric values you want directly, using octal ("\015"), hex
Even though with normal text files, a "\n" will do the trick, there is
still no unified scheme for terminating a line that is portable
-between Unix, MS-DOS/Windows, and Macintosh, except to terminate I<ALL> line
+between Unix, DOS/Win, and Macintosh, except to terminate I<ALL> line
ends with "\015\012", and strip what you don't need from the output.
This applies especially to socket I/O and autoflushing, discussed
next.
@@ -208,7 +208,7 @@ You don't actually "trap" a control character. Instead, that
character generates a signal, which you then trap. Signals are
documented in L<perlipc/"Signals"> and chapter 6 of the Camel.
-Be warned that very few C libraries are reentrant. Therefore, if you
+Be warned that very few C libraries are re-entrant. Therefore, if you
attempt to print() in a handler that got invoked during another stdio
operation your internal structures will likely be in an
inconsistent state, and your program will dump core. You can
@@ -230,7 +230,7 @@ For example:
However, because syscalls restart by default, you'll find that if
you're in a "slow" call, such as E<lt>FHE<gt>, read(), connect(), or
wait(), that the only way to terminate them is by "longjumping" out;
-that is, by raising an exception. See the timeout handler for a
+that is, by raising an exception. See the time-out handler for a
blocking flock() in L<perlipc/"Signals"> or chapter 6 of the Camel.
=head2 How do I modify the shadow password file on a Unix system?
@@ -311,7 +311,7 @@ END blocks you should also use
Perl's exception-handling mechanism is its eval() operator. You can
use eval() as setjmp and die() as longjmp. For details of this, see
-the section on signals, especially the timeout handler for a blocking
+the section on signals, especially the time-out handler for a blocking
flock() in L<perlipc/"Signals"> and chapter 6 of the Camel.
If exception handling is all you're interested in, try the
@@ -352,7 +352,7 @@ Simple files like F<errno.h>, F<syscall.h>, and F<socket.h> were fine,
but the hard ones like F<ioctl.h> nearly always need to hand-edited.
Here's how to install the *.ph files:
- 1. become superuser
+ 1. become super-user
2. cd /usr/include
3. h2ph *.h */*.h
@@ -381,14 +381,14 @@ documentation, though (see L<IPC::Open2>).
=head2 Why can't I get the output of a command with system()?
-You're confusing the purpose of system() and backticks (''). system()
-runs a command and returns exit status information (as a 16 bit value
--- the low 8 bits are the signal the process died from, if any, and
-the high 8 bits are the actual exit value). Backticks ('') run a
+You're confusing the purpose of system() and backticks (``). system()
+runs a command and returns exit status information (as a 16 bit value:
+the low 8 bits are the signal the process died from, if any, and
+the high 8 bits are the actual exit value). Backticks (``) run a
command and return what it sent to STDOUT.
- $status = system("mail-users");
- $output = `ls`;
+ $exit_status = system("mail-users");
+ $output_string = `ls`;
=head2 How can I capture STDERR from an external command?
@@ -552,14 +552,32 @@ Things that are awkward to do in the shell are easy to do in Perl, and
this very awkwardness is what would make a shell->perl converter
nigh-on impossible to write. By rewriting it, you'll think about what
you're really trying to do, and hopefully will escape the shell's
-pipeline data stream paradigm, which while convenient for some matters,
+pipeline datastream paradigm, which while convenient for some matters,
causes many inefficiencies.
=head2 Can I use perl to run a telnet or ftp session?
-Try the Net::FTP and TCP::Client modules (available from CPAN).
-http://www.perl.com/CPAN/scripts/netstuff/telnet.emul.shar will also
-help for emulating the telnet protocol.
+Try the Net::FTP, TCP::Client, and Net::Telnet modules (available from
+CPAN). http://www.perl.com/CPAN/scripts/netstuff/telnet.emul.shar
+will also help for emulating the telnet protocol, but Net::Telnet is
+quite probably easier to use..
+
+If all you want to do is pretend to be telnet but don't need
+the initial telnet handshaking, then the standard dual-process
+approach will suffice:
+
+ use IO::Socket; # new in 5.004
+ $handle = IO::Socket::INET->new('www.perl.com:80')
+ || die "can't connect to port 80 on www.perl.com: $!";
+ $handle->autoflush(1);
+ if (fork()) { # XXX: undef means failure
+ select($handle);
+ print while <STDIN>; # everything from stdin to socket
+ } else {
+ print while <$handle>; # everything from socket to stdout
+ }
+ close $handle;
+ exit;
=head2 How can I write expect in Perl?
@@ -619,7 +637,7 @@ module for other solutions.
=item *
-Open /dev/tty and use the TIOCNOTTY ioctl on it. See L<tty(4)>
+Open /dev/tty and use the the TIOCNOTTY ioctl on it. See L<tty(4)>
for details.
=item *
@@ -643,20 +661,6 @@ Background yourself like this:
See the F<eg/nih> script (part of the perl source distribution).
-=head2 How do I keep my own module/library directory?
-
-When you build modules, use the PREFIX option when generating
-Makefiles:
-
- perl Makefile.PL PREFIX=/u/mydir/perl
-
-then either set the PERL5LIB environment variable before you run
-scripts that use the modules/libraries (see L<perlrun>) or say
-
- use lib '/u/mydir/perl';
-
-See Perl's L<lib> for more information.
-
=head2 How do I find out if I'm running interactively or not?
Good question. Sometimes C<-t STDIN> and C<-t STDOUT> can give clues,
@@ -754,7 +758,42 @@ If your version of perl is compiled without dynamic loading, then you
just need to replace step 3 (B<make>) with B<make perl> and you will
get a new F<perl> binary with your extension linked in.
-See L<ExtUtils::MakeMaker> for more details on building extensions.
+See L<ExtUtils::MakeMaker> for more details on building extensions,
+the question "How do I keep my own module/library directory?"
+
+=head2 How do I keep my own module/library directory?
+
+When you build modules, use the PREFIX option when generating
+Makefiles:
+
+ perl Makefile.PL PREFIX=/u/mydir/perl
+
+then either set the PERL5LIB environment variable before you run
+scripts that use the modules/libraries (see L<perlrun>) or say
+
+ use lib '/u/mydir/perl';
+
+See Perl's L<lib> for more information.
+
+=head2 How do I add the directory my program lives in to the module/library search path?
+
+ use FindBin;
+ use lib "$FindBin:Bin";
+ use your_own_modules;
+
+=head2 How do I add a directory to my include path at runtime?
+
+Here are the suggested ways of modifying your include path:
+
+ the PERLLIB environment variable
+ the PERL5LIB environment variable
+ the perl -Idir commpand line flag
+ the use lib pragma, as in
+ use lib "$ENV{HOME}/myown_perllib";
+
+The latter is particularly useful because it knows about machine
+dependent architectures. The lib.pm pragmatic module was first
+included with the 5.002 release of Perl.
=head1 AUTHOR AND COPYRIGHT
diff --git a/pod/perlfaq9.pod b/pod/perlfaq9.pod
index 9e6355f816..f4f4759ba5 100644
--- a/pod/perlfaq9.pod
+++ b/pod/perlfaq9.pod
@@ -1,6 +1,6 @@
=head1 NAME
-perlfaq9 - Networking ($Revision: 1.15 $, $Date: 1997/03/25 18:17:20 $)
+perlfaq9 - Networking ($Revision: 1.16 $, $Date: 1997/04/23 18:12:06 $)
=head1 DESCRIPTION
@@ -62,9 +62,10 @@ A quick but imperfect approach is
}gsix;
This version does not adjust relative URLs, understand alternate
-bases, deal with HTML comments, or accept URLs themselves as
-arguments. It also runs about 100x faster than a more "complete"
-solution using the LWP suite of modules, such as the
+bases, deal with HTML comments, deal with HREF and NAME attributes in
+the same tag, or accept URLs themselves as arguments. It also runs
+about 100x faster than a more "complete" solution using the LWP suite
+of modules, such as the
http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/xurl.gz
program.
@@ -83,14 +84,30 @@ others, including some that it cleverly synthesizes on its own.
=head2 How do I fetch an HTML file?
-Use the LWP::Simple module available from CPAN, part of the excellent
-libwww-perl (LWP) package. On the other hand, and if you have the
-lynx text-based HTML browser installed on your system, this isn't too
-bad:
+One approach, if you have the lynx text-based HTML browser installed
+on your system, is this:
$html_code = `lynx -source $url`;
$text_data = `lynx -dump $url`;
+The libwww-perl (LWP) modules from CPAN provide a more powerful way to
+do this. They work through proxies, and don't require lynx:
+
+ # print HTML from a URL
+ use LWP::Simple;
+ getprint "http://www.sn.no/libwww-perl/";
+
+ # print ASCII from HTML from a URL
+ use LWP::Simple;
+ use HTML::Parse;
+ use HTML::FormatText;
+ my ($html, $ascii);
+ $html = get("http://www.perl.com/");
+ defined $html
+ or die "Can't fetch HTML from http://www.perl.com/";
+ $ascii = HTML::FormatText->new->format(parse_html($html));
+ print $ascii;
+
=head2 how do I decode or create those %-encodings on the web?
Here's an example of decoding:
@@ -127,7 +144,7 @@ server, or perhaps check some of the other FAQs referenced above.
The HTTPD::UserAdmin and HTTPD::GroupAdmin modules provide a
consistent OO interface to these files, regardless of how they're
-stored. Databases may be text, dbm, Berkeley DB or any database with a
+stored. Databases may be text, dbm, Berkley DB or any database with a
DBI compatible driver. HTTPD::UserAdmin supports files used by the
`Basic' and `Digest' authentication schemes. Here's an example:
@@ -136,6 +153,19 @@ DBI compatible driver. HTTPD::UserAdmin supports files used by the
->new(DB => "/foo/.htpasswd")
->add($username => $password);
+=head2 How do I make sure users can't enter values into a form that cause my CGI script to do bad things?
+
+Read the CGI security FAQ, at
+http://www-genome.wi.mit.edu/WWW/faqs/www-security-faq.html, and the
+Perl/CGI FAQ at
+http://www.perl.com/CPAN/doc/FAQs/cgi/perl-cgi-faq.html.
+
+In brief: use tainting (see L<perlsec>), which makes sure that data
+from outside your script (eg, CGI parameters) are never used in
+C<eval> or C<system> calls. In addition to tainting, never use the
+single-argument form of system() or exec(). Instead, supply the
+command and arguments as a list, which prevents shell globbing.
+
=head2 How do I parse an email header?
For a quick-and-dirty solution, try this solution derived
@@ -185,6 +215,12 @@ comments), looks for addresses you may not wish to accept email to
(say, Bill Clinton or your postmaster), and then makes sure that the
hostname given can be looked up in DNS. It's not fast, but it works.
+Here's an alternative strategy used by many CGI script authors: Check
+the email address with a simple regexp (such as the one above). If
+the regexp matched the address, accept the address. If the regexp
+didn't match the address, request confirmation from the user that the
+email address they entered was correct.
+
=head2 How do I decode a MIME/BASE64 string?
The MIME-tools package (available from CPAN) handles this and a lot
@@ -224,8 +260,8 @@ Again, the best way is often just to ask the user.
=head2 How do I send/read mail?
Sending mail: the Mail::Mailer module from CPAN (part of the MailTools
-package) is Unix-centric, while Mail::Internet uses Net::SMTP which is
-not Unix-centric. Reading mail: use the Mail::Folder module from CPAN
+package) is UNIX-centric, while Mail::Internet uses Net::SMTP which is
+not UNIX-centric. Reading mail: use the Mail::Folder module from CPAN
(part of the MailFolder package) or the Mail::Internet module from
CPAN (also part of the MailTools package).
@@ -292,3 +328,4 @@ CPAN). No ONC::RPC module is known.
Copyright (c) 1997 Tom Christiansen and Nathan Torkington.
All rights reserved. See L<perlfaq> for distribution information.
+
diff --git a/pod/perlguts.pod b/pod/perlguts.pod
index 7b4e4c718b..de71460917 100644
--- a/pod/perlguts.pod
+++ b/pod/perlguts.pod
@@ -34,19 +34,21 @@ An SV can be created and loaded with one command. There are four types of
values that can be loaded: an integer value (IV), a double (NV), a string,
(PV), and another scalar (SV).
-The four routines are:
+The five routines are:
SV* newSViv(IV);
SV* newSVnv(double);
SV* newSVpv(char*, int);
+ SV* newSVpvf(const char*, ...);
SV* newSVsv(SV*);
-To change the value of an *already-existing* SV, there are five routines:
+To change the value of an *already-existing* SV, there are six routines:
void sv_setiv(SV*, IV);
void sv_setnv(SV*, double);
- void sv_setpvn(SV*, char*, int)
void sv_setpv(SV*, char*);
+ void sv_setpvn(SV*, char*, int)
+ void sv_setpvf(SV*, const char*, ...);
void sv_setsv(SV*, SV*);
Notice that you can choose to specify the length of the string to be
@@ -54,7 +56,8 @@ assigned by using C<sv_setpvn> or C<newSVpv>, or you may allow Perl to
calculate the length by using C<sv_setpv> or by specifying 0 as the second
argument to C<newSVpv>. Be warned, though, that Perl will determine the
string's length by using C<strlen>, which depends on the string terminating
-with a NUL character.
+with a NUL character. The arguments of C<sv_setpvf> are processed like
+C<sprintf>, and the formatted output becomes the value.
All SVs that will contain strings should, but need not, be terminated
with a NUL character. If it is not NUL-terminated there is a risk of
@@ -119,13 +122,15 @@ you can use the following functions:
void sv_catpv(SV*, char*);
void sv_catpvn(SV*, char*, int);
+ void sv_catpvf(SV*, const char*, ...);
void sv_catsv(SV*, SV*);
The first function calculates the length of the string to be appended by
using C<strlen>. In the second, you specify the length of the string
-yourself. The third function extends the string stored in the first SV
-with the string stored in the second SV. It also forces the second SV to
-be interpreted as a string.
+yourself. The third function processes its arguments like C<sprintf> and
+appends the formatted output. The fourth function extends the string
+stored in the first SV with the string stored in the second SV. It also
+forces the second SV to be interpreted as a string.
If you know the name of a scalar variable, you can get a pointer to its SV
by using the following:
@@ -2236,6 +2241,13 @@ C<len> indicates number of bytes to copy.
void sv_catpvn _((SV* sv, char* ptr, STRLEN len));
+=item sv_catpvf
+
+Processes its arguments like C<sprintf> and appends the formatted output
+to an SV.
+
+ void sv_catpvf _((SV* sv, const char* pat, ...));
+
=item sv_catsv
Concatenates the string from SV C<ssv> onto the end of the string in SV
@@ -2615,6 +2627,13 @@ bytes to be copied.
void sv_setpvn _((SV* sv, char* ptr, STRLEN len));
+=item sv_setpvf
+
+Processes its arguments like C<sprintf> and sets an SV to the formatted
+output.
+
+ void sv_setpvf _((SV* sv, const char* pat, ...));
+
=item sv_setref_iv
Copies an integer into a new SV, optionally blessing the SV. The C<rv>
diff --git a/pod/perltie.pod b/pod/perltie.pod
index 847340d182..ccc1156982 100644
--- a/pod/perltie.pod
+++ b/pod/perltie.pod
@@ -611,7 +611,7 @@ use the each() function to iterate over such. Example:
This is partially implemented now.
A class implementing a tied filehandle should define the following
-methods: TIEHANDLE, at least one of PRINT, READLINE, GETC, or READ,
+methods: TIEHANDLE, at least one of PRINT, PRINTF, READLINE, GETC, or READ,
and possibly DESTROY.
It is especially useful when perl is embedded in some other program,
@@ -634,12 +634,26 @@ hold some internal information.
=item PRINT this, LIST
-This method will be triggered every time the tied handle is printed to.
+This method will be triggered every time the tied handle is printed to
+with the C<print()> function.
Beyond its self reference it also expects the list that was passed to
the print function.
sub PRINT { $r = shift; $$r++; print join($,,map(uc($_),@_)),$\ }
+=item PRINTF this, LIST
+
+This method will be triggered every time the tied handle is printed to
+with the C<printf()> function.
+Beyond its self reference it also expects the format and list that was
+passed to the printf function.
+
+ sub PRINTF {
+ shift;
+ my $fmt = shift;
+ print sprintf($fmt, @_)."\n";
+ }
+
=item READ this LIST
This method will be called when the handle is read from via the C<read>
@@ -832,4 +846,4 @@ source code to MLDBM.
Tom Christiansen
-TIEHANDLE by Sven Verdoolaege <F<skimo@dns.ufsia.ac.be>>
+TIEHANDLE by Sven Verdoolaege <F<skimo@dns.ufsia.ac.be>> and Doug MacEachern <F<dougm@osf.org>>
diff --git a/pod/perltoc.pod b/pod/perltoc.pod
index 388a672f50..a70ed6e74e 100644
--- a/pod/perltoc.pod
+++ b/pod/perltoc.pod
@@ -38,8 +38,8 @@ expression enhancements, Innumerable Unbundled Modules, Compilability
=item NOTES
-=head2 perlfaq - frequently asked questions about Perl ($Date: 1997/03/25
-18:20:48 $)
+=head2 perlfaq - frequently asked questions about Perl ($Date: 1997/04/23
+18:11:06 $)
=item DESCRIPTION
@@ -76,7 +76,8 @@ authors
=item Changes
-25/March/97, 18/March/97, 17/March/97 Version, Initial Release: 11/March/97
+23/April/97, 25/March/97, 18/March/97, 17/March/97 Version, Initial
+Release: 11/March/97
=head2 perlfaq1 - General Questions About Perl ($Revision: 1.11 $, $Date:
1997/03/19 17:23:09 $)
@@ -119,8 +120,8 @@ Scheme, or Tcl?
=item AUTHOR AND COPYRIGHT
-=head2 perlfaq2 - Obtaining and Learning about Perl ($Revision: 1.15 $,
-$Date: 1997/03/25 18:15:48 $)
+=head2 perlfaq2 - Obtaining and Learning about Perl ($Revision: 1.16 $,
+$Date: 1997/04/23 18:04:09 $)
=item DESCRIPTION
@@ -175,8 +176,8 @@ MacPerl, Perl5-Porters, NTPerl, Perl-Packrats
=item AUTHOR AND COPYRIGHT
-=head2 perlfaq3 - Programming Tools ($Revision: 1.20 $, $Date: 1997/03/19
-17:23:43 $)
+=head2 perlfaq3 - Programming Tools ($Revision: 1.21 $, $Date: 1997/04/23
+18:04:23 $)
=item DESCRIPTION
@@ -226,11 +227,11 @@ MacPerl, Perl5-Porters, NTPerl, Perl-Packrats
=item How can I compile my Perl program into byte code or C?
-=item How can I get '#!perl' to work on [MS-DOS,Windows NT,...]?
+=item How can I get '#!perl' to work on [MS-DOS,NT,...]?
=item Can I write useful perl programs on the command line?
-=item Why don't perl one-liners work on my MS-DOS/Macintosh/VMS system?
+=item Why don't perl one-liners work on my DOS/Mac/VMS system?
=item Where can I learn about CGI or Web programming in Perl?
@@ -250,8 +251,8 @@ mean?
=item AUTHOR AND COPYRIGHT
-=head2 perlfaq4 - Data Manipulation ($Revision: 1.17 $, $Date: 1997/03/25
-18:16:24 $)
+=head2 perlfaq4 - Data Manipulation ($Revision: 1.18 $, $Date: 1997/04/23
+18:04:37 $)
=item DESCRIPTION
@@ -259,6 +260,9 @@ mean?
=over
+=item Why am I getting long decimals (eg, 19.9499999999999) instead of the
+numbers I should be getting (eg, 19.95)?
+
=item Why isn't my octal data interpreted correctly?
=item Does perl have a round function? What about ceil() and floor()?
@@ -441,8 +445,8 @@ or array of hashes or arrays?
=item AUTHOR AND COPYRIGHT
-=head2 perlfaq5 - Files and Formats ($Revision: 1.20 $, $Date: 1997/03/19
-17:24:51 $)
+=head2 perlfaq5 - Files and Formats ($Revision: 1.21 $, $Date: 1997/04/23
+18:05:19 $)
=item DESCRIPTION
@@ -511,7 +515,7 @@ in the file. How can I do this?
=item How do I close a file descriptor by number?
-=item Why can't I use "C:\temp\foo" in MS-DOS paths? What doesn't
+=item Why can't I use "C:\temp\foo" in DOS paths? What doesn't
`C:\temp\foo.exe` work?
=item Why doesn't glob("*.*") get all the files?
@@ -619,6 +623,8 @@ commas?
=item What's a closure?
+=item What is variable suicide and how can I prevent it?
+
=item How can I pass/return a {Function, FileHandle, Array, Hash, Method,
Regexp}?
@@ -649,12 +655,14 @@ is in scope?
=item How can I find out my current package?
+=item How can I comment out a large block of perl code?
+
=back
=item AUTHOR AND COPYRIGHT
-=head2 perlfaq8 - System Interaction ($Revision: 1.17 $, $Date: 1997/03/25
-18:17:12 $)
+=head2 perlfaq8 - System Interaction ($Revision: 1.20 $, $Date: 1997/04/23
+18:11:50 $)
=item DESCRIPTION
@@ -738,8 +746,6 @@ complete?
=item How do I make my program run with sh and csh?
-=item How do I keep my own module/library directory?
-
=item How do I find out if I'm running interactively or not?
=item How do I timeout a slow event?
@@ -756,11 +762,18 @@ complete?
=item How do I install a CPAN module?
+=item How do I keep my own module/library directory?
+
+=item How do I add the directory my program lives in to the module/library
+search path?
+
+=item How do I add a directory to my include path at runtime?
+
=back
=item AUTHOR AND COPYRIGHT
-=head2 perlfaq9 - Networking ($Revision: 1.15 $, $Date: 1997/03/25 18:17:20
+=head2 perlfaq9 - Networking ($Revision: 1.16 $, $Date: 1997/04/23 18:12:06
$)
=item DESCRIPTION
@@ -789,6 +802,9 @@ file on another machine?
=item How do I edit my .htpasswd and .htgroup files with Perl?
+=item How do I make sure users can't enter values into a form that cause my
+CGI script to do bad things?
+
=item How do I parse an email header?
=item How do I decode a CGI form?
@@ -871,8 +887,8 @@ isa(CLASS), can(METHOD), VERSION( [NEED] )
=item TIEHANDLE now supported
-TIEHANDLE classname, LIST, PRINT this, LIST, READ this LIST, READLINE this,
-GETC this, DESTROY this
+TIEHANDLE classname, LIST, PRINT this, LIST, PRINTF this, LIST, READ this
+LIST, READLINE this, GETC this, DESTROY this
=item Malloc enhancements
@@ -1774,8 +1790,8 @@ this, NEXTKEY this, lastkey, DESTROY this
=item Tying FileHandles
-TIEHANDLE classname, LIST, PRINT this, LIST, READ this LIST, READLINE this,
-GETC this, DESTROY this
+TIEHANDLE classname, LIST, PRINT this, LIST, PRINTF this, LIST, READ this
+LIST, READLINE this, GETC this, DESTROY this
=item The C<untie> Gotcha
@@ -2346,21 +2362,22 @@ perl_require_pv, perl_run, POPi, POPl, POPp, POPn, POPs, PUSHMARK, PUSHi,
PUSHn, PUSHp, PUSHs, PUTBACK, Renew, Renewc, RETVAL, safefree, safemalloc,
saferealloc, savepv, savepvn, SAVETMPS, SP, SPAGAIN, ST, strEQ, strGE,
strGT, strLE, strLT, strNE, strnEQ, strnNE, sv_2mortal, sv_bless, sv_catpv,
-sv_catpvn, sv_catsv, sv_cmp, sv_cmp, SvCUR, SvCUR_set, sv_dec, sv_dec,
-SvEND, sv_eq, SvGROW, sv_grow, sv_inc, SvIOK, SvIOK_off, SvIOK_on,
+sv_catpvn, sv_catpvf, sv_catsv, sv_cmp, sv_cmp, SvCUR, SvCUR_set, sv_dec,
+sv_dec, SvEND, sv_eq, SvGROW, sv_grow, sv_inc, SvIOK, SvIOK_off, SvIOK_on,
SvIOK_only, SvIOK_only, SvIOKp, sv_isa, SvIV, sv_isobject, SvIVX, SvLEN,
sv_len, sv_len, sv_magic, sv_mortalcopy, SvOK, sv_newmortal, sv_no, SvNIOK,
SvNIOK_off, SvNIOKp, SvNOK, SvNOK_off, SvNOK_on, SvNOK_only, SvNOK_only,
SvNOKp, SvNV, SvNVX, SvPOK, SvPOK_off, SvPOK_on, SvPOK_only, SvPOK_only,
SvPOKp, SvPV, SvPVX, SvREFCNT, SvREFCNT_dec, SvREFCNT_inc, SvROK,
SvROK_off, SvROK_on, SvRV, sv_setiv, sv_setnv, sv_setpv, sv_setpvn,
-sv_setref_iv, sv_setref_nv, sv_setref_pv, sv_setref_pvn, sv_setsv, SvSTASH,
-SVt_IV, SVt_PV, SVt_PVAV, SVt_PVCV, SVt_PVHV, SVt_PVMG, SVt_NV, SvTRUE,
-SvTYPE, svtype, SvUPGRADE, sv_upgrade, sv_undef, sv_unref, sv_usepvn,
-sv_yes, THIS, toLOWER, toUPPER, warn, XPUSHi, XPUSHn, XPUSHp, XPUSHs, XS,
-XSRETURN, XSRETURN_EMPTY, XSRETURN_IV, XSRETURN_NO, XSRETURN_NV,
-XSRETURN_PV, XSRETURN_UNDEF, XSRETURN_YES, XST_mIV, XST_mNV, XST_mNO,
-XST_mPV, XST_mUNDEF, XST_mYES, XS_VERSION, XS_VERSION_BOOTCHECK, Zero
+sv_setpvf, sv_setref_iv, sv_setref_nv, sv_setref_pv, sv_setref_pvn,
+sv_setsv, SvSTASH, SVt_IV, SVt_PV, SVt_PVAV, SVt_PVCV, SVt_PVHV, SVt_PVMG,
+SVt_NV, SvTRUE, SvTYPE, svtype, SvUPGRADE, sv_upgrade, sv_undef, sv_unref,
+sv_usepvn, sv_yes, THIS, toLOWER, toUPPER, warn, XPUSHi, XPUSHn, XPUSHp,
+XPUSHs, XS, XSRETURN, XSRETURN_EMPTY, XSRETURN_IV, XSRETURN_NO,
+XSRETURN_NV, XSRETURN_PV, XSRETURN_UNDEF, XSRETURN_YES, XST_mIV, XST_mNV,
+XST_mNO, XST_mPV, XST_mUNDEF, XST_mYES, XS_VERSION, XS_VERSION_BOOTCHECK,
+Zero
=item EDITOR