=head1 NAME
-perlfaq1 - General Questions About Perl ($Revision: 1.7 $, $Date: 2002/02/21 14:49:15 $)
+perlfaq1 - General Questions About Perl ($Revision: 1.8 $, $Date: 2002/04/07 18:46:13 $)
=head1 DESCRIPTION
producing better software for free than you could hope to purchase for
money. You may snoop on pending developments via the archives at
http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/
-and http://archive.develooper.com/perl5-porters@perl.org/
+and http://archive.develooper.com/perl5-porters@perl.org/
or the news gateway nntp://nntp.perl.org/perl.perl5.porters or
its web interface at http://nntp.perl.org/group/perl.perl5.porters ,
or read the faq at http://perlhacker.org/p5p-faq ,
=head1 NAME
-perlfaq2 - Obtaining and Learning about Perl ($Revision: 1.9 $, $Date: 2002/03/09 21:01:13 $)
+perlfaq2 - Obtaining and Learning about Perl ($Revision: 1.11 $, $Date: 2002/04/08 15:39:59 $)
=head1 DESCRIPTION
There is also a Usenet gateway to Perl mailing lists sponsored by perl.org at
nntp://nntp.perl.org, or a web interface to the same lists at
-http://nntp.perl.org/group/ . Other groups are listed at
-http://lists.perl.org/
+http://nntp.perl.org/group/. Other groups are listed at
+http://lists.perl.org/ .
=head2 Where should I post source code?
see their FAQ ( http://www.faqs.org/faqs/alt-sources-intro/ ) for details.
If you're just looking for software, first use Google
-( http://www.google.com/ ), Google's usenet search interface
-( http://groups.google.com/ ), and CPAN Search ( http://search.cpan.org/ ).
+( http://www.google.com ), Google's usenet search interface
+( http://groups.google.com ), and CPAN Search ( http://search.cpan.org ).
This is faster and more productive than just posting a request.
=head2 Perl Books
expressions, and networking, and sponsors the Obfuscated Perl Contest
and the Perl Poetry Contests. As of mid-2001, the dead tree version
of TPJ will be published as a quarterly supplement of SysAdmin
-magazine ( http://www.sysadmin.com/ ) For more details on TPJ,
+magazine ( http://www.sysadminmag.com/ ) For more details on TPJ,
see http://www.tpj.com/
Beyond this, magazines that frequently carry quality articles on
To get the best performance, pick a site from
the list below and use it to grab the complete list of mirror sites
-which is at /CPAN/MIRRORED.BY or at http://mirror.cpan.org/
+which is at /CPAN/MIRRORED.BY or at http://mirror.cpan.org/ .
From there you can find the quickest site for you. Remember, the
following list is I<not> the complete list of CPAN mirrors
(the complete list contains 165 sites as of January 2001):
ftp://ftp.uvsq.fr/pub/perl/CPAN/
ftp://ftp.funet.fi/pub/languages/perl/CPAN/
ftp://ftp.dti.ad.jp/pub/lang/CPAN/
- ftp://mirror.aarnet.edu.au/pub/perl/CPAN/
ftp://cpan.if.usp.br/pub/mirror/CPAN/
One may also use xx.cpan.org where "xx" is the 2-letter country code
=head1 NAME
-perlfaq3 - Programming Tools ($Revision: 1.15 $, $Date: 2002/02/11 19:29:52 $)
+perlfaq3 - Programming Tools ($Revision: 1.17 $, $Date: 2002/04/08 15:39:59 $)
=head1 DESCRIPTION
as it were. A more complete example, with comments, can be found at
http://www.cpan.org/authors/id/TOMC/scripts/toms.exrc.gz
-The a2ps http://www-inf.enst.fr/%7Edemaille/a2ps/black+white.ps.gz does
+The a2ps http://www-inf.enst.fr/%7Edemaille/a2ps/black+white.ps does
lots of things related to generating nicely printed output of
-documents, as does enscript at http://people.ssh.fi/mtr/genscript/
+documents, as does enscript at http://people.ssh.fi/mtr/genscript/ .
=head2 Is there a ctags for Perl?
=item The Object System
-( http://www.castlelink.co.uk/object_system/ ) is a Perl web
+(http://www.castlelink.co.uk/object_system/) is a Perl web
applications development IDE, apparently for any platform
that runs Perl.
Only". You can also download text editors designed
specifically for programming, such as Textpad
( http://www.textpad.com/ ) and UltraEdit
-( http://www.ultraedit.com/ ), among others.
+( http://www.ultraedit.com ), among others.
If you are using MacOS, the same concerns apply. MacPerl
(for Classic environments) comes with a simple editor.
-Popular external editors are BBEdit ( http://www.bbedit.com/ )
+Popular external editors are BBEdit ( http://www.bbedit.com )
or Alpha ( http://alpha.olm.net/ ). MacOS X users can use Unix
editors as well.
=back
For vi lovers in general, Windows or elsewhere:
-http://www.thomer.com/thomer/vi/vi.html
+
+ http://www.thomer.com/thomer/vi/vi.html
nvi ( http://www.bostic.com/vi/ , available from CPAN in src/misc/) is
yet another vi clone, unfortunately not available for Windows, but in
see http://www.cpan.org/authors/Tom_Christiansen/scripts/toms.exrc.gz ,
the standard benchmark file for vi emulators. The file runs best with nvi,
the current version of vi out of Berkeley, which incidentally can be built
-with an embedded Perl interpreter--see http://www.cpan.org/src/misc/
+with an embedded Perl interpreter--see http://www.cpan.org/src/misc .
=head2 Where can I get perl-mode for emacs?
http://perl.apache.org/
With the FCGI module (from CPAN) and the mod_fastcgi
-module ( available from http://www.fastcgi.com/ ) each of your Perl
+module (available from http://www.fastcgi.com/) each of your Perl
programs becomes a permanent CGI daemon process.
Both of these solutions can have far-reaching effects on your system
=head1 NAME
-perlfaq4 - Data Manipulation ($Revision: 1.19 $, $Date: 2002/03/11 22:15:19 $)
+perlfaq4 - Data Manipulation ($Revision: 1.20 $, $Date: 2002/04/07 18:46:13 $)
=head1 DESCRIPTION
If you either have Perl 5.8.0 or later installed, or if you have
Scalar-List-Utils 1.03 or later installed, you can say:
- use List::Util 'shuffle';
+ use List::Util 'shuffle';
@shuffled = shuffle(@list);
-If not, you can use this:
+If not, you can use a Fisher-Yates shuffle.
- # fisher_yates_shuffle
- # generate a random permutation of an array in place
- # As in shuffling a deck of cards
- #
sub fisher_yates_shuffle {
my $deck = shift; # $deck is a reference to an array
my $i = @$deck;
- while (--$i) {
+ while ($i--) {
my $j = int rand ($i+1);
@$deck[$i,$j] = @$deck[$j,$i];
}
}
-And here is an example of using it:
-
- #
# shuffle my mpeg collection
#
my @mpeg = <audio/*/*.mp3>;
=head1 NAME
-perlfaq5 - Files and Formats ($Revision: 1.12 $, $Date: 2002/03/11 22:25:25 $)
+perlfaq5 - Files and Formats ($Revision: 1.14 $, $Date: 2002/04/07 18:33:45 $)
=head1 DESCRIPTION
which allow you to tie an array to a file so that accessing an element
the array actually accesses the corresponding line in the file.
-On very rare occasion, you may have an algorithm that demands that
-the entire file be in memory at once as one scalar. The simplest solution
-to that is
-
- $var = `cat $file`;
-
-Being in scalar context, you get the whole thing. In list context,
-you'd get a list of all the lines:
-
- @lines = `cat $file`;
-
-This tiny but expedient solution is neat, clean, and portable to
-all systems on which decent tools have been installed. For those
-who prefer not to use the toolbox, you can of course read the file
-manually, although this makes for more complicated code.
+You can read the entire filehandle contents into a scalar.
{
local(*INPUT, $/);
$var = do { local $/; <INPUT> };
+For ordinary files you can also use the read function.
+
+ read( INPUT, $var, -s INPUT );
+
+The third argument tests the byte size of the data on the INPUT filehandle
+and reads that many bytes into the buffer $var.
+
=head2 How can I read in a file by paragraphs?
Use the C<$/> variable (see L<perlvar> for details). You can either
=head1 NAME
-perlfaq6 - Regular Expressions ($Revision: 1.8 $, $Date: 2002/01/31 04:27:55 $)
+perlfaq6 - Regular Expressions ($Revision: 1.10 $, $Date: 2002/04/07 18:32:57 $)
=head1 DESCRIPTION
=head2 What's wrong with using grep or map in a void context?
-Both grep and map build a return list, regardless of their context.
-This means you're making Perl go to the trouble of building up a
-return list that you then just ignore. That's no way to treat a
-programming language, you insensitive scoundrel!
+The problem is that both grep and map build a return list,
+regardless of the context. This means you're making Perl go
+to the trouble of building a list that you then just throw away.
+If the list is large, you waste both time and space. If your
+intent is to iterate over the list then use a for loop for this
+purpose.
=head2 How can I match strings with multibyte characters?
=head1 NAME
-perlfaq7 - General Perl Language Issues ($Revision: 1.7 $, $Date: 2002/01/31 04:27:55 $)
+perlfaq7 - General Perl Language Issues ($Revision: 1.8 $, $Date: 2002/03/26 15:48:32 $)
=head1 DESCRIPTION
=head2 How can I comment out a large block of perl code?
-Use embedded POD to discard it:
+You can use embedded POD to discard it. The =for directive
+lasts until the next paragraph (two consecutive newlines).
# program is here
# program continues
+The =begin and =end directives can contain multiple
+paragraphs.
+
=begin comment text
all of this stuff
=end comment text
- =cut
+The pod directives cannot go just anywhere. You must put a
+pod directive where the parser is expecting a new statement,
+not just in the middle of an expression or some other
+arbitrary s grammar production.
-This can't go just anywhere. You have to put a pod directive where
-the parser is expecting a new statement, not just in the middle
-of an expression or some other arbitrary yacc grammar production.
+See L<perlpod> for more details.
=head2 How do I clear a package?
=head1 NAME
-perlfaq9 - Networking ($Revision: 1.7 $, $Date: 2002/01/28 04:17:27 $)
+perlfaq9 - Networking ($Revision: 1.9 $, $Date: 2002/04/07 18:46:13 $)
=head1 DESCRIPTION
s/([^\w()'*~!.-])/sprintf '%%%02x', ord $1/eg; # encode
- s/%([A-Fa-f\d]{2})/chr hex $1/eg; # decode
+ s/%([A-Fa-f\d]{2})/chr hex $1/eg; # decode
However, you should only apply them to individual URI components, not
the entire URI, otherwise you'll lose information and generally mess