From: Jarkko Hietaniemi Date: Mon, 8 Oct 2001 23:31:21 +0000 (+0000) Subject: FAQ sync. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bc06af7496abc68809dea149d963eea3f2e007f9;p=p5sagit%2Fp5-mst-13.2.git FAQ sync. p4raw-id: //depot/perl@12369 --- diff --git a/pod/perlfaq3.pod b/pod/perlfaq3.pod index efa764d..4085684 100644 --- a/pod/perlfaq3.pod +++ b/pod/perlfaq3.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq3 - Programming Tools ($Revision: 1.4 $, $Date: 2001/10/02 19:42:02 $) +perlfaq3 - Programming Tools ($Revision: 1.6 $, $Date: 2001/10/03 23:06:15 $) =head1 DESCRIPTION @@ -164,9 +164,13 @@ related to generating nicely printed output of documents. =head2 Is there a ctags for Perl? -There's a simple one at +Recent versions of ctags do much more than older versions did. +EXUBERANT CTAGS is available from http://ctags.sourceforge.net/ +and does a good job of making tags files for perl code. + +There is also a simple one at http://www.perl.com/CPAN/authors/id/TOMC/scripts/ptags.gz which may do -the trick. And if not, it's easy to hack into what you want. +the trick. It can be easy to hack this into what you want. =head2 Is there an IDE or Windows Perl Editor? @@ -519,6 +523,51 @@ When the files you're processing are small, it doesn't much matter which way you do it, but it makes a huge difference when they start getting larger. +=item * Use map and grep selectively + +Remember that both map and grep expect a LIST argument, so doing this: + + @wanted = grep {/pattern/} ; + +will cause the entire file to be slurped. For large files, it's better +to loop: + + while () { + push(@wanted, $_) if /pattern/; + } + +=item * Avoid unnecessary quotes and stringification + +Don't quote large strings unless absolutely necessary: + + my $copy = "$large_string"; + +makes 2 copies of $large_string (one for $copy and another for the +quotes), whereas + + my $copy = $large_string; + +only makes one copy. + +Ditto for stringifying large arrays: + + { + local $, = "\n"; + print @big_array; + } + +is much more memory-efficient than either + + print join "\n", @big_array; + +or + + { + local $" = "\n"; + print "@big_array"; + } + + =item * Pass by reference Pass arrays and hashes by reference, not by value. For one thing, it's diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod index 72eb8d8..195248b 100644 --- a/pod/perlfaq4.pod +++ b/pod/perlfaq4.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq4 - Data Manipulation ($Revision: 1.2 $, $Date: 2001/09/26 15:42:12 $) +perlfaq4 - Data Manipulation ($Revision: 1.3 $, $Date: 2001/10/03 23:08:02 $) =head1 DESCRIPTION @@ -507,6 +507,15 @@ Use Text::Wrap (part of the standard Perl distribution): The paragraphs you give to Text::Wrap should not contain embedded newlines. Text::Wrap doesn't justify the lines (flush-right). +Or use the CPAN module Text::Autoformat. Formatting files can be easily +done by making a shell alias, like so: + + alias fmt="perl -i -MText::Autoformat -n0777 \ + -e 'print autoformat $_, {all=>1}' $*" + +See the documentation for Text::Autoformat to appreciate its many +capabilities. + =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