=head1 NAME
-perlfaq - frequently asked questions about Perl ($Date: 2001/09/20 03:03:00 $)
+perlfaq - frequently asked questions about Perl ($Date: 2001/10/16 13:27:22 $)
=head1 DESCRIPTION
=item 7/January/99
-Small touchups here and there. Added all questions in this
+Small touch ups here and there. Added all questions in this
document as a sort of table of contents.
=item 22/June/98
=head1 NAME
-perlfaq2 - Obtaining and Learning about Perl ($Revision: 1.1 $, $Date: 2001/09/20 03:03:00 $)
+perlfaq2 - Obtaining and Learning about Perl ($Revision: 1.2 $, $Date: 2001/10/16 13:27:22 $)
=head1 DESCRIPTION
user community and an extensive literature. The comp.lang.perl.*
newsgroups and several of the mailing lists provide free answers to your
questions in near real-time. Perl has traditionally been supported by
-Larry, scores of software designers and developers, and myriads of
+Larry, scores of software designers and developers, and myriad
programmers, all working for free to create a useful thing to make life
better for everyone.
=head1 NAME
-perlfaq3 - Programming Tools ($Revision: 1.7 $, $Date: 2001/10/09 22:17:53 $)
+perlfaq3 - Programming Tools ($Revision: 1.8 $, $Date: 2001/10/17 14:14:20 $)
=head1 DESCRIPTION
see the two especially dedicated to web stuff in the question on
books. For problems and questions related to the web, like ``Why
do I get 500 Errors'' or ``Why doesn't it run from the browser right
-when it runs fine on the command line'', see these sources:
-
- WWW Security FAQ
- http://www.w3.org/Security/Faq/
-
- Web FAQ
- http://www.boutell.com/faq/
-
- CGI FAQ
- http://www.webthing.com/tutorials/cgifaq.html
-
- HTTP Spec
- http://www.w3.org/pub/WWW/Protocols/HTTP/
-
- HTML Spec
- http://www.w3.org/TR/REC-html40/
- http://www.w3.org/pub/WWW/MarkUp/
-
- CGI Spec
- http://www.w3.org/CGI/
-
- CGI Security FAQ
- http://www.go2net.com/people/paulp/cgi-security/safe-cgi.txt
+when it runs fine on the command line'', see the troubleshooting
+guides and references in L<perlfaq9> or in the CGI MetaFAQ:
+ http://www.perl.org/CGI_MetaFAQ.html
+
=head2 Where can I learn about object-oriented Perl programming?
A good place to start is L<perltoot>, and you can use L<perlobj>,
=head1 NAME
-perlfaq5 - Files and Formats ($Revision: 1.2 $, $Date: 2001/09/26 10:44:41 $)
+perlfaq5 - Files and Formats ($Revision: 1.3 $, $Date: 2001/10/16 13:27:22 $)
=head1 DESCRIPTION
$document = join('', <$sock>);
print "DOC IS: $document\n";
-Note the bizarrely hardcoded carriage return and newline in their octal
+Note the bizarrely hard coded carriage return and newline in their octal
equivalents. This is the ONLY way (currently) to assure a proper flush
on all platforms, including Macintosh. That's the way things work in
network programming: you really should specify the exact bit pattern
We've used C<$$var> in a way that forbidden by C<use strict 'refs'>.
That is, we've promoted a string to a scalar variable reference using
-symbolic references. This is ok in small programs, but doesn't scale
+symbolic references. This is okay in small programs, but doesn't scale
well. It also only works on global variables, not lexicals.
=head2 How can I make a filehandle local to a subroutine? How do I pass filehandles between subroutines? How do I make an array of filehandles?
before using it. That is because only simple scalar variables, not
expressions or subscripts of hashes or arrays, can be used with
built-ins like C<print>, C<printf>, or the diamond operator. Using
-something other than a simple scalar varaible as a filehandle is
+something other than a simple scalar variable as a filehandle is
illegal and won't even compile:
@fd = (*STDIN, *STDOUT, *STDERR);
does implement append mode correctly (a local filesystem on a modern
Unix for example), and you keep the file in block-buffered mode and you
write less than one buffer-full of output between each manual flushing
-of the buffer then each bufferload is almost garanteed to be written to
+of the buffer then each bufferload is almost guaranteed to be written to
the end of the file in one chunk without getting intermingled with
anyone else's output. You can also use the syswrite() function which is
simply a wrapper around your systems write(2) system call.
If you want to retrieve the time at which the file was last read,
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
+B<-A>, or B<-C> file test 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"
time in seconds since the epoch, you would call the stat function,
% ./fionread
0x4004667f
-And then hard-code it, leaving porting as an exercise to your successor.
+And then hard code it, leaving porting as an exercise to your successor.
$FIONREAD = 0x4004667f; # XXX: opsys dependent
=head1 NAME
-perlfaq6 - Regexes ($Revision: 1.1 $, $Date: 2001/09/20 03:03:00 $)
+perlfaq6 - Regexes ($Revision: 1.3 $, $Date: 2001/10/16 13:27:22 $)
=head1 DESCRIPTION
print;
-And here it is as a subroutine, modelled after the above:
+And here it is as a subroutine, modeled after the above:
sub preserve_case($$) {
my ($old, $new) = @_;
=head2 Can I use Perl regular expressions to match balanced text?
-Although Perl regular expressions are more powerful than "mathematical"
-regular expressions because they feature conveniences like backreferences
-(C<\1> and its ilk), they still aren't powerful enough--with
-the possible exception of bizarre and experimental features in the
-development-track releases of Perl. You still need to use non-regex
-techniques to parse balanced text, such as the text enclosed between
-matching parentheses or braces, for example.
+Historically, Perl regular expressions were not capable of matching
+balanced text. As of more recent versions of perl including 5.6.1
+experimental features have been added that make it possible to do this.
+Look at the documentation for the (??{ }) construct in recent perlre manual
+pages to see an example of matching balanced parentheses. Be sure to take
+special notice of the warnings present in the manual before making use
+of this feature.
+
+CPAN contains many modules that can be useful for matching text
+depending on the context. Damian Conway provides some useful
+patterns in Regexp::Common. The module Text::Balanced provides a
+general solution to this problem.
+
+One of the common applications of balanced text matching is working
+with XML and HTML. There are many modules available that support
+these needs. Two examples are HTML::Parser and XML::Parser. There
+are many others.
An elaborate subroutine (for 7-bit ASCII only) to pull out balanced
and possibly nested single chars, like C<`> and C<'>, C<{> and C<}>,
or C<(> and C<)> can be found in
http://www.perl.com/CPAN/authors/id/TOMC/scripts/pull_quotes.gz .
-The C::Scan module from CPAN contains such subs for internal use,
+The C::Scan module from CPAN also contains such subs for internal use,
but they are undocumented.
=head2 What does it mean that regexes are greedy? How can I get around it?
=head1 NAME
-perlfaq7 - Perl Language Issues ($Revision: 1.1 $, $Date: 2001/09/20 03:03:00 $)
+perlfaq7 - Perl Language Issues ($Revision: 1.2 $, $Date: 2001/10/16 13:27:22 $)
=head1 DESCRIPTION
# if using RCS/CVS, this next line may be preferred,
# but beware two-digit versions.
- $VERSION = do{my@r=q$Revision: 1.1 $=~/\d+/g;sprintf '%d.'.'%02d'x$#r,@r};
+ $VERSION = do{my@r=q$Revision: 1.2 $=~/\d+/g;sprintf '%d.'.'%02d'x$#r,@r};
@ISA = qw(Exporter);
@EXPORT = qw(&func1 &func2 &func3);
Here's a simple example of a switch based on pattern matching, this
time lined up in a way to make it look more like a switch statement.
-We'll do a multi-way conditional based on the type of reference stored
+We'll do a multiway conditional based on the type of reference stored
in $whatchamacallit:
SWITCH: for (ref $whatchamacallit) {
=head1 NAME
-perlfaq8 - System Interaction ($Revision: 1.1 $, $Date: 2001/09/20 03:03:00 $)
+perlfaq8 - System Interaction ($Revision: 1.2 $, $Date: 2001/10/16 13:27:22 $)
=head1 DESCRIPTION
DEV->autoflush(1);
As mentioned in the previous item, this still doesn't work when using
-socket I/O between Unix and Macintosh. You'll need to hardcode your
+socket I/O between Unix and Macintosh. You'll need to hard code your
line terminators, in that case.
=item non-blocking input
basis.) This mechanism will work for Unix, MS-DOS, Windows, and NT;
the VMS equivalent is C<set time>.
-However, if all you want to do is change your timezone, you can
+However, if all you want to do is change your time zone, you can
probably get away with setting an environment variable:
$ENV{TZ} = "MST7MDT"; # unixish
=head1 NAME
-perlfaq9 - Networking ($Revision: 1.2 $, $Date: 2001/09/28 06:40:07 $)
+perlfaq9 - Networking ($Revision: 1.3 $, $Date: 2001/10/16 13:27:22 $)
=head1 DESCRIPTION
The Mail::Internet module uses Net::SMTP which is less Unix-centric than
Mail::Mailer, but less reliable. Avoid raw SMTP commands. There
are many reasons to use a mail transport agent like sendmail. These
-include queueing, MX records, and security.
+include queuing, MX records, and security.
=head2 How do I use MIME to make an attachment to a mail message?