'perlfaq' => {
'MAINTAINER' => 'perlfaq',
- 'DISTRIBUTION' => 'LLAP/perlfaq-5.0150037.tar.gz',
+ 'DISTRIBUTION' => 'LLAP/perlfaq-5.0150038.tar.gz',
'FILES' => q[cpan/perlfaq],
'EXCLUDED' => [
qw( t/release-pod-syntax.t
package perlfaq;
{
- $perlfaq::VERSION = '5.0150037';
+ $perlfaq::VERSION = '5.0150038';
}
0; # not is it supposed to be loaded
L<https://github.com/perl-doc-cats/perlfaq>.
Once approved, changes are merged into L<https://github.com/tpf/perlfaq>, the
-repository which drives L<http://learn.perl.org/faq/>, and they are
+repository which drives L<http://learn.perl.org/faq/>, and they are
distributed with the next Perl 5 release.
=head2 What if my question isn't answered in the FAQ?
=item *
+How do I find the user's mail address?
+
+=item *
+
How do I send email?
=item *
Tom Christiansen wrote the original perlfaq then expanded it with the
help of Nat Torkington. brian d foy substantialy edited and expanded
-the perlfaq. perlfaq-workers and others have also supplied feedback,
+the perlfaq. perlfaq-workers and others have also supplied feedback,
patches and corrections over the years.
=head1 AUTHOR AND COPYRIGHT
=head2 What is Perl?
Perl is a high-level programming language with an eclectic heritage
-written by Larry Wall and a cast of thousands.
+written by Larry Wall and a cast of thousands.
Perl's process, file, and text manipulation facilities make it
particularly well-suited for tasks involving quick prototyping, system
utilities, software tools, system management tasks, database access,
graphical programming, networking, and web programming.
-Perl derives from the ubiquitous C programming language and to a
-lesser extent from sed, awk, the Unix shell, and many other tools
+Perl derives from the ubiquitous C programming language and to a
+lesser extent from sed, awk, the Unix shell, and many other tools
and languages.
These strengths make it especially popular with web developers
and system administrators. Mathematicians, geneticists, journalists,
-managers and many other people also use Perl.
+managers and many other people also use Perl.
=head2 Who supports Perl? Who develops it? Why is it free?
The core development team (known as the Perl Porters)
are a group of highly altruistic individuals committed to
producing better software for free than you could hope to purchase for
-money. You may snoop on pending developments via the
+money. You may snoop on pending developments via the
L<archives|http://www.nntp.perl.org/group/perl.perl5.porters/>
or read the L<faq|http://dev.perl.org/perl5/docs/p5p-faq.html>,
or you can subscribe to the mailing list by sending
The current major release of Perl is Perl 5, first released in
1994. It can run scripts from the previous major release, Perl 4
-(March 1991), but has significant differences.
+(March 1991), but has significant differences.
Perl 6 is a reinvention of Perl, it is a language in the same lineage but
-not compatible. The two are complementary, not mutually exclusive. Perl 6 is
-not meant to replace Perl 5, and vice versa. See L</"What is Perl 6?"> below
+not compatible. The two are complementary, not mutually exclusive. Perl 6 is
+not meant to replace Perl 5, and vice versa. See L</"What is Perl 6?"> below
to find out more.
See L<perlhist> for a history of Perl revisions.
=head2 What is Perl 6?
Perl 6 was I<originally> described as the community's rewrite of Perl 5.
-Development started in 2002; syntax and design work continue to this day.
-As the language has evolved, it has become clear that it is a separate
-language, incompatible with Perl 5 but in the same language family.
-
-Contrary to popular belief, Perl 6 and Perl 5 peacefully coexist with one
-another. Perl 6 has proven to be a fascinating source of ideas for those
-using Perl 5 (the L<Moose> object system is a well-known example). There is
-overlap in the communities, and this overlap fosters the tradition of sharing
-and borrowing that have been instrumental to Perl's success. The current
-leading implementation of Perl 6 is Rakudo, and you can learn more about
+Development started in 2002; syntax and design work continue to this day.
+As the language has evolved, it has become clear that it is a separate
+language, incompatible with Perl 5 but in the same language family.
+
+Contrary to popular belief, Perl 6 and Perl 5 peacefully coexist with one
+another. Perl 6 has proven to be a fascinating source of ideas for those
+using Perl 5 (the L<Moose> object system is a well-known example). There is
+overlap in the communities, and this overlap fosters the tradition of sharing
+and borrowing that have been instrumental to Perl's success. The current
+leading implementation of Perl 6 is Rakudo, and you can learn more about
it at L<http://rakudo.org>.
If you want to learn more about Perl 6, or have a desire to help in
=head2 How does Perl compare with other languages like Java, Python, REXX, Scheme, or Tcl?
-Perl can be used for almost any coding problem, even ones which require
+Perl can be used for almost any coding problem, even ones which require
integrating specialist C code for extra speed. As with any tool it can
be used well or badly. Perl has many strengths, and a few weaknesses,
-precisely which areas are good and bad is often a personal choice.
+precisely which areas are good and bad is often a personal choice.
-When choosing a language you should also be influenced by the
-L<resources|http://www.cpan.org/>, L<testing culture|http://www.cpantesters.org/>
+When choosing a language you should also be influenced by the
+L<resources|http://www.cpan.org/>, L<testing culture|http://www.cpantesters.org/>
and L<community|http://www.perl.org/community.html> which surrounds it.
For comparisons to a specific language it is often best to create
certain task (e.g. prolog, make).
If you find that you need to speed up a specific part of a Perl
-application (not something you often need) you may want to use C,
+application (not something you often need) you may want to use C,
but you can access this from your Perl code with L<perlxs>.
=head2 What's the difference between "perl" and "Perl"?
-"Perl" is the name of the language. Only the "P" is capitalized.
+"Perl" is the name of the language. Only the "P" is capitalized.
The name of the interpreter (the program which runs the Perl script)
is "perl" with a lowercase "p".
=head2 I don't have a C compiler. How can I build my own Perl interpreter?
-For Windows, use a binary version of Perl,
+For Windows, use a binary version of Perl,
L<Strawberry Perl|http://strawberryperl.com/> and
L<ActivePerl|http://www.activestate.com/activeperl> come with a
bundled C compiler.
-Otherwise if you really do want to build Perl, you need to get a
-binary version of C<gcc> for your system first. Use a search
+Otherwise if you really do want to build Perl, you need to get a
+binary version of C<gcc> for your system first. Use a search
engine to find out how to do this for your operating system.
=head2 I copied the Perl binary from one machine to another, but scripts don't work.
CPAN stands for Comprehensive Perl Archive Network, a multi-gigabyte
archive replicated on hundreds of machines all over the world. CPAN
-contains tens of thousands of modules and extensions, source code
-and documentation, designed for I<everything> from commercial
+contains tens of thousands of modules and extensions, source code
+and documentation, designed for I<everything> from commercial
database interfaces to keyboard/screen control and running large web sites.
You can search CPAN on L<http://metacpan.org> or
L<http://search.cpan.org/>.
-The master web site for CPAN is L<http://www.cpan.org/>,
+The master web site for CPAN is L<http://www.cpan.org/>,
L<http://www.cpan.org/SITES.html> lists all mirrors.
See the CPAN FAQ at L<http://www.cpan.org/misc/cpan-faq.html> for answers
advocacy site for the Perl language. It uses the domain to provide
general support services to the Perl community, including the hosting
of mailing lists, web sites, and other services. There are also many
-other sub-domains for special topics like learning Perl and jobs in Perl,
+other sub-domains for special topics like learning Perl and jobs in Perl,
such as:
=over 4
=back
-L<Perl Mongers|http://www.pm.org/> uses the pm.org domain for services
-related to local Perl user groups, including the hosting of mailing lists
-and web sites. See the L<Perl Mongers web site|http://www.pm.org/> for more
-information about joining, starting, or requesting services for a
+L<Perl Mongers|http://www.pm.org/> uses the pm.org domain for services
+related to local Perl user groups, including the hosting of mailing lists
+and web sites. See the L<Perl Mongers web site|http://www.pm.org/> for more
+information about joining, starting, or requesting services for a
Perl user group.
CPAN, or the Comprehensive Perl Archive Network L<http://www.cpan.org/>,
=head2 Which Perl blogs should I read?
L<Perl News|http://perlnews.org/> covers some of the major events in the Perl
-world, L<Perl Weekly|http://perlweekly.com/> is a weekly e-mail
+world, L<Perl Weekly|http://perlweekly.com/> is a weekly e-mail
(and RSS feed) of hand-picked Perl articles.
L<http://blogs.perl.org/> hosts many Perl blogs, there are also
in releases and comes in well-defined packages. There is a very large
and supportive user community and an extensive literature.
-If you still need commercial support
+If you still need commercial support
L<ActiveState|http://www.activestate.com/activeperl> offers
this.
sends the message to the right place.
To determine if a module came with your version of Perl, you can
-install and use the L<Module::CoreList> module. It has the information
-about the modules (with their versions) included with each release
+install and use the L<Module::CoreList> module. It has the information
+about the modules (with their versions) included with each release
of Perl.
Every CPAN module has a bug tracker set up in RT, L<http://rt.cpan.org>.
=item Various
-L<http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz>
-(not a man-page but still useful, a collection of various essays on
+L<http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz>
+(not a man-page but still useful, a collection of various essays on
Perl techniques)
=back
backtraces, check variable values, set breakpoints, and other
operations typically found in symbolic debuggers.
-You can also use L<Devel::REPL> which is an interactive shell for Perl,
+You can also use L<Devel::REPL> which is an interactive shell for Perl,
commonly known as a REPL - Read, Evaluate, Print, Loop. It provides
various handy features.
=head2 Is there a pretty-printer (formatter) for Perl?
-L<Perl::Tidy> comes with a perl script L<perltidy> which indents and
-reformats Perl scripts to make them easier to read by trying to follow
+L<Perl::Tidy> comes with a perl script L<perltidy> which indents and
+reformats Perl scripts to make them easier to read by trying to follow
the rules of the L<perlstyle>. If you write Perl, or spend much time reading
Perl, you will probably find it useful.
performance with minimal changes, or can be used along with modern Perl web
frameworks to make writing and deploying web services with Perl a breeze.
-These solutions can have far-reaching effects on your system and on the way you
+These solutions can have far-reaching effects on your system and on the way you
write your CGI programs, so investigate them with care.
See also
push(@results, some_func($i));
}
-or even
+or even
push(@results, some_func($_)) for 5 .. 500_005;
course, living in a state of sin."
Perl relies on the underlying system for the implementation of
-C<rand> and C<srand>; on some systems, the generated numbers are
-not random enough (especially on Windows : see
-L<http://www.perlmonks.org/?node_id=803632>).
+C<rand> and C<srand>; on some systems, the generated numbers are
+not random enough (especially on Windows : see
+L<http://www.perlmonks.org/?node_id=803632>).
Several CPAN modules in the C<Math> namespace implement better
-pseudorandom generators; see for example
-L<Math::Random::MT> ("Mersenne Twister", fast), or
-L<Math::TrulyRandom> (uses the imperfections in the system's
+pseudorandom generators; see for example
+L<Math::Random::MT> ("Mersenne Twister", fast), or
+L<Math::TrulyRandom> (uses the imperfections in the system's
timer to generate random numbers, which is rather slow).
-More algorithms for random numbers are described in
+More algorithms for random numbers are described in
"Numerical Recipes in C" at L<http://www.nr.com/>
=head2 How do I get a random number between X and Y?
L<< (?PARNO)|perlre/C<(?PARNO)> C<(?-PARNO)> C<(?+PARNO)> C<(?R)> C<(?0)> >>
construct (available since perl 5.10).
The CPAN module L<Regexp::Common> can help to build such
-regular expressions (see in particular
+regular expressions (see in particular
L<Regexp::Common::balanced> and L<Regexp::Common::delimited>).
More complex cases will require to write a parser, probably
using a parsing module from CPAN, like
-L<Regexp::Grammars>, L<Parse::RecDescent>, L<Parse::Yapp>,
-L<Text::Balanced>, or L<Marpa>.
+L<Regexp::Grammars>, L<Parse::RecDescent>, L<Parse::Yapp>,
+L<Text::Balanced>, or L<Marpa::XS>.
=head2 How do I reverse a string?
=head2 How can I prevent addition of unwanted keys into a hash?
Since version 5.8.0, hashes can be I<restricted> to a fixed number
-of given keys. Methods for creating and dealing with restricted hashes
+of given keys. Methods for creating and dealing with restricted hashes
are exported by the L<Hash::Util> module.
=head1 Data: Misc
approach will suffice:
use IO::Socket; # new in 5.004
- my $handle = IO::Socket::INET->new('L<www.perl.com:80')>
- or die "can't connect to port 80 on L<www.perl.com:> $!";
+ my $handle = IO::Socket::INET->new('www.perl.com:80')
+ or die "can't connect to port 80 on www.perl.com $!";
$handle->autoflush(1);
if (fork()) { # XXX: undef means failure
select($handle);
=head2 Should I use a web framework?
-Yes. If you are building a web site with any level of interactivity
+Yes. If you are building a web site with any level of interactivity
(forms / users / databases), you
will want to use a framework to make handling requests
and responses easier.
If there is no interactivity then you may still want
to look at using something like L<Template Toolkit|https://metacpan.org/module/Template>
-or L<Plack::Middleware::TemplateToolkit>
+or L<Plack::Middleware::TemplateToolkit>
so maintenance of your HTML files (and other assets) is easier.
=head2 Which web framework should I use?
X<framework> X<CGI.pm> X<CGI> X<Catalyst> X<Dancer>
-There are many Perl web frameworks, e.g. :
+There is no simple answer to this question. Perl frameworks can run everything
+from basic file servers and small scale intranets to massive multinational
+multilingual websites that are the core to international businesses.
+
+Below is a list of a few frameworks with comments which might help you in
+making a decision, depending on your specific requirements. Start by reading
+the docs, then ask questions on the relevant mailing list or IRC channel.
=over 4
-=item L<Web::Simple> - A quick and easy way to build simple web applications
+=item L<Catalyst>
-=item L<Dancer> - Lightweight yet powerful web application framework
+Strongly object-oriented and fully-featured with a long development history and
+a large community and addon ecosystem. It is excellent for large and complex
+applications, where you have full control over the server.
-=item L<Catalyst> - Elegant MVC Web Application Framework
+=item L<Dancer>
-=back
+Young and free of legacy weight, providing a lightweight and easy to learn API.
+Has a growing addon ecosystem. It is best used for smaller projects and
+very easy to learn for beginners.
+
+=item L<Mojolicious>
+
+Fairly young with a focus on HTML5 and real-time web technologies such as
+WebSockets.
-These are just a few of the more widely used ones. All of them
-interact with or use L<Plack> which is worth understanding
-the basics of, as there is a lot of useful
-L<Plack::Middleware|https://metacpan.org/search?q=plack%3A%3Amiddleware>.
+=item L<Web::Simple>
+
+Currently experimental, strongly object-oriented, built for speed and intended
+as a toolkit for building micro web apps, custom frameworks or for tieing
+together existing Plack-compatible web applications with one central dispatcher.
+
+=back
-As to which one you should use, it depends on the complexity
-of the site you are trying to build. Review the three listed
-above and see which suites your needs best. Many of them share the
-same L<MVC|http://en.wikipedia.org/wiki/Model-view-controller>
-concepts so once you understand one it is easier to understand
-the others.
+All of these interact with or use L<Plack> which is worth understanding
+the basics of when building a website in Perl (there is a lot of useful
+L<Plack::Middleware|https://metacpan.org/search?q=plack%3A%3Amiddleware>).
=head2 What is Plack and PSGI?
L<PSGI> is the Perl Web Server Gateway Interface Specification, it is
-a standard that many Perl web frameworks use, you should not need to
+a standard that many Perl web frameworks use, you should not need to
understand it to build a web site, the part you might want to use is L<Plack>.
-L<Plack> is a set of tools for using the PSGI stack. It contains
-L<middleware|https://metacpan.org/search?q=plack%3A%3Amiddleware>
-components, a reference server and utilities for Web application frameworks.
+L<Plack> is a set of tools for using the PSGI stack. It contains
+L<middleware|https://metacpan.org/search?q=plack%3A%3Amiddleware>
+components, a reference server and utilities for Web application frameworks.
Plack is like Ruby's Rack or Python's Paste for WSGI.
You could build a web site using L<Plack> and your own code,
-but for anything other than a very basic web site, using a web framework
+but for anything other than a very basic web site, using a web framework
(that uses L<Plack>) is a better option.
=head2 How do I remove HTML from a string?
-Use L<HTML::Strip>, or L<HTML::FormatText> which not only removes HTML
-but also attempts to do a little simple formatting of the resulting
+Use L<HTML::Strip>, or L<HTML::FormatText> which not only removes HTML
+but also attempts to do a little simple formatting of the resulting
plain text.
=head2 How do I extract URLs?
-L<HTML::SimpleLinkExtor> will extract URLs from HTML, it handles anchors,
-images, objects, frames, and many other tags that can contain a URL.
+L<HTML::SimpleLinkExtor> will extract URLs from HTML, it handles anchors,
+images, objects, frames, and many other tags that can contain a URL.
If you need anything more complex, you can create your own subclass of
L<HTML::LinkExtor> or L<HTML::Parser>. You might even use
L<HTML::SimpleLinkExtor> as an example for something specifically
your web framework, or if you are making a request,
the L<LWP> or other module would handle it for you.
-To encode a string yourself, use the L<URI::Escape> module. The C<uri_escape>
+To encode a string yourself, use the L<URI::Escape> module. The C<uri_escape>
function returns the escaped string:
my $original = "Colon : Hash # Percent %";
$c->res->redirect($url);
$c->detach();
-
+
If you are using Plack (which most frameworks do), then
L<Plack::Middleware::Rewrite> is worth looking at if you
are migrating from Apache or have URL's you want to always
The L<Email::MIME> module can decode base 64-encoded email message parts
transparently so the developer doesn't need to worry about it.
+=head2 How do I find the user's mail address?
+
+Ask them for it. There are so many email providers available that it's
+unlikely the local system has any idea how to determine a user's email address.
+
+The exception is for organization-specific email (e.g. foo@yourcompany.com)
+where policy can be codified in your program. In that case, you could look at
+$ENV{USER}, $ENV{LOGNAME}, and getpwuid($<) in scalar context, like so:
+
+ my $user_name = getpwuid($<)
+
+But you still cannot make assumptions about whether this is correct, unless
+your policy says it is. You really are best off asking the user.
+
=head2 How do I send email?
Use the L<Email::MIME> and L<Email::Sender::Simple> modules, like so:
This is like the SMTP transport, but uses TLS security. You can
authenticate with this module as well, using any mechanisms your server
-supports after STARTTLS.
+supports after STARTTLS.
=back
=item XS
-A language to extend Perl with L<C> and C++. XS is an interface description
-file format used to create an extension interface between
-Perl and C code (or a C library) which one wishes to use with Perl.
+A language to extend Perl with L<C> and C++. XS is an interface description
+file format used to create an extension interface between
+Perl and C code (or a C library) which one wishes to use with Perl.
See L<perlxs> for the exact explanation or read the L<perlxstut>
tutorial.
=item *
-L<perlfaq> has been upgraded from version 5.0150036 to version 5.0150037.
+L<perlfaq> has been upgraded from version 5.0150036 to version 5.0150038.
=item *