Permalink
Browse files

Merge branch 'master' of git@github.com:chromatic/modern_perl_book

Conflicts:
	CREDITS
  • Loading branch information...
2 parents 43aad0a + b391ccf commit 5c596e664d09b8ef9e28a5567b4cbbc889b39a25 @chromatic committed Jun 30, 2010
View
@@ -71,3 +71,6 @@ E: mike.hind@gmail.com
N: Frank Wiegand
E: fwie@cpan.org
+
+N: Shawn M Moore
+E: sartak@bestpractical.com
View
@@ -17,7 +17,7 @@ solve your problems as you see fit.
Perl is a language which can grow with you. You can write useful programs with
the knowledge that you can learn in an hour of reading this book. Yet if you
-take the time to understand the philsophies behind the syntax, semantics, and
+take the time to understand the philosophies behind the syntax, semantics, and
design of the language, you can be ten times as productive.
First, you need to know how to learn more.
View
@@ -20,7 +20,7 @@ L<anonymous_functions>
L<closures>
-L<state_versus_closures>
+L<state>
L<attributes>
View
@@ -19,10 +19,10 @@ mean>), though you must be specific about your intentions.
Z<boolean_coercion>
X<coercion; boolean>
-Boolean coercion occurs when you test the truth of a value, such as in a C<if>
-or C<while> condition. Numeric 0 is false. The undefined value is false. The
-empty string is false, and so is the string C<'0'>. The strings C<'0.0'> and
-C<'0e'> are I<true>, however.
+Boolean coercion occurs when you test the truthiness of a value, such as in a
+C<if> or C<while> condition. Numeric 0 is false. The undefined value is
+false. The empty string is false, and so is the string C<'0'>. The strings
+C<'0.0'> and C<'0e'> are I<true>, however.
All other values are true, including the idiomatic string C<'0 but true'>. In
the case of a scalar with both string and numeric portions (L<dualvars>), Perl
@@ -109,9 +109,9 @@ stringification and a numificationN<This is a simplification, but the gory
details are truly gory.>. Stringifying a numeric value does not replace the
numeric value with a string. Instead, it I<attaches> a stringified value to
the value in addition to the numeric value. The same sort of operation happens
-when numifiying a string value.
+when numifying a string value.
-You almost never need to know that this happpens--perhaps once or twice a
+You almost never need to know that this happens--perhaps once or twice a
decade, if anecdotal evidence is admissible.
Perl 5 may prefer one form over another. If a value has a cached
View
@@ -38,7 +38,7 @@ value:
=end programlisting
-This postfix form is useful for simple expressions. A block block form groups
+This postfix form is useful for simple expressions. A block form groups
multiple expressions into a single unit:
=begin programlisting
@@ -271,7 +271,7 @@ subsequent subexpressions. This is most obvious with an example:
=begin programlisting
say "Both true!" if ok(1, 'first subexpression')
- && ok(1, 'second subexpression' );
+ && ok(1, 'second subexpression');
=end programlisting
@@ -300,7 +300,7 @@ subsequent subexpressions:
=begin programlisting
say "Both true!" if ok(0, 'first subexpression')
- && ok(1, 'second subexpression' );
+ && ok(1, 'second subexpression');
=end programlisting
@@ -319,7 +319,7 @@ either subexpression must be true for the conditional as a whole to succeed:
=begin programlisting
say "Either true!" if ok(1, 'first subexpression')
- || ok(1, 'second subexpression' );
+ || ok(1, 'second subexpression');
=end programlisting
@@ -567,12 +567,11 @@ through C<$_>.
X<for loop>
-The I<for-style loop> allows the programmer to manage iteration conditions
-manually:
+The I<for-style loop> allows the programmer to manage iteration manually:
=begin programlisting
- for (my $i = 0; $i <= 10; ++$i)
+ for (my $i = 0; $i <= 10; $i += 2)
{
say "$i * $i = ", $i * $i;
}
@@ -589,7 +588,7 @@ section of this construct I<will> overwrite its contents:
my $i = 'pig';
- for ($i = 0; $i <= 10; ++$i)
+ for ($i = 0; $i <= 10; $i += 2)
{
say "$i * $i = ", $i * $i;
}
@@ -835,7 +834,7 @@ to exhaust a filehandle with a C<while> loop:
Opening the filehandle outside of the C<for> loop leaves the file position
unchanged between each iteration of the C<for> loop. On its second iteration,
the C<while> loop will have nothing to read and will not execute. To solve
-this problem, You may re-open the file inside the C<for> loop (simple to
+this problem, you may re-open the file inside the C<for> loop (simple to
understand, but not always a good use of system resources), slurp the entire
file into memory (which may not work if the file is large), or C<seek> the
filehandle back to the beginning of the file for each iteration (an overlooked
@@ -884,7 +883,7 @@ once you've seen the ending delimiter, you might write:
X<redo>
-The I<redo> statement restarts the current iteration without evaluting the
+The I<redo> statement restarts the current iteration without evaluating the
conditional again. This can be useful in those few cases where you want to
modify the line you've read in place, then start processing over from the
beginning without clobbering it with another line. For example, you could
View
@@ -202,7 +202,7 @@ rest to another function:
=end programlisting
The dominant practice seems to be to use C<shift> only when your function must
-access a single paramater and list assignment when accessing multiple
+access a single parameter and list assignment when accessing multiple
parameters.
=head3 Flattening
@@ -23,7 +23,7 @@ X<-w>
X<command-line arguments; -w>
Lexical encapsulation of warnings is as important as lexical encapsulation of
-variables. Older code may use the C<-w> command line argument to enable
+variables. Older code may use the C<-w> command-line argument to enable
warnings throughout the program, even if other code has not specifically
attempted to suppress warnings. It's all or nothing. If you have the
wherewithal to eliminate warnings and potential warnings throughout the entire
View
@@ -234,8 +234,8 @@ contains the given key:
Using C<exists> instead of accessing the hash key directly avoids two problems.
First, it does not check the boolean nature of the hash I<value>; a hash key
-may exist with a value even if that value evaluates to a boolean false.
-Second, with nested data structures, it avoids autovivifying
+may exist with a value even if that value evaluates to a boolean false (including
+C<undef>). Second, with nested data structures, it avoids autovivifying
(L<autovivification>) the value.
=head3 Accessing Hash Keys and Values
@@ -544,9 +544,9 @@ You can even set default parameters with this approach:
sub make_sundae
{
my %parameters = @_;
- B<$parameters{flavor} = 'Vanilla';>
- B<$parameters{topping} = 'fudge';>
- B<$parameters{sprinkles} = 100;>
+ B<$parameters{flavor} //= 'Vanilla';>
+ B<$parameters{topping} //= 'fudge';>
+ B<$parameters{sprinkles} //= 100;>
...
}
@@ -563,7 +563,7 @@ You can even set default parameters with this approach:
B<< flavor => 'Vanilla', >>
B<< topping => 'fudge', >>
B<< sprinkles => 100, >>
- @
+ @_,
);
...
}
@@ -85,7 +85,7 @@ arrays or hashes requires disambiguation blocks:
=end programlisting
-Similarly, slicing a nested data structure requires additional puncutation:
+Similarly, slicing a nested data structure requires additional punctuation:
=begin programlisting
@@ -96,7 +96,7 @@ documentation should make this clear.
For example, the arithmetic operators are binary operators, and are usually
left associative. C<2 + 3 - 4> evaluates C<2 + 3> first; addition and
subtraction have the same precedence, but they're left associative and binary,
-so the proper evaluation order applies the leftmost operator (C<+>) to the the
+so the proper evaluation order applies the leftmost operator (C<+>) to the
leftmost two operands (C<2> and C<3>) with the leftmost operator (C<+>), then
applies the rightmost operator (C<->) to the result of the first operation and
the rightmost operand (C<4>).
View
@@ -39,7 +39,7 @@ call the C<add_box()> function only by C<MyCode::add_box()>. A fully qualified
name includes its complete package name.
The default package is the C<main> package. If you do not declare a package
-explicitly, whether in a one-liner on a command line or in a standalone Perl
+explicitly, whether in a one-liner on a command-line or in a standalone Perl
program or even in a F<.pm> file on disk, the current package will be the
C<main> package.
@@ -99,8 +99,8 @@ X<namespaces>
Every C<package> declaration causes Perl to perform two tasks. It creates a
new namespace if that namespace does not already exist. It also tells the
-parser to put all package global symbols (global variables and functions) into
-that namespace.
+parser to put all subsequent package global symbols (global variables and
+functions) into that namespace.
X<namespaces; open>
X<open namespaces>
@@ -66,7 +66,7 @@ interesting and useful Perl news on a regular basis.
X<RT>
X<Best Practical>
-Best Practical Consulting (U<http://bestpractical.com/>) maintains an
+Best Practical Solutions (U<http://bestpractical.com/>) maintains an
installation of their popular request tracking system, RT, for CPAN authors as
well as Perl 5 and Perl 6 development. Every CPAN distribution has its own RT
queue, linked from C<search.cpan.org> and available on U<http://rt.cpan.org/>.
View
@@ -121,7 +121,7 @@ X<subs pragma>
First, they are often necessary to emulate and override built-in keywords with
user-defined functions. You must first check that you I<can> override the
-built-in keywod by checking that C<prototype> does not return C<undef>. Once
+built-in keyword by checking that C<prototype> does not return C<undef>. Once
you know the prototype of the keyword, use a forward declaration of a function
with the same name as the core keyword:
View
@@ -519,7 +519,7 @@ When the counter reaches zero, Perl can safely recycle that value.
Within the inner block in the example, there's one C<$fh>. (Multiple lines in
the source code refer to it, but there's only one I<reference> to it; C<$fh>
itself.) C<$fh> is only in scope in the block and does not get assigned to
-anyting outside of the block, so when the block ends, its reference count
+anything outside of the block, so when the block ends, its reference count
reaches zero. The recycling of C<$fh> calls an implicit C<close()> method on
the filehandle, and so the file gets closed.
View
@@ -369,7 +369,7 @@ list context without using a temporary variable, you use the idiom (L<idioms>):
=end programlisting
Because of the right associativity (L<associativity>) of the assignment
-operator, Perl first evalutes the second assignment by calling
+operator, Perl first evaluates the second assignment by calling
C<get_all_clown_hats()> in list context. This produces a list. Even though
that list never gets assigned to anything, the return value of the second
assignment is that list. Perl next evaluates that list in scalar context, due
@@ -444,8 +444,9 @@ whitespace to produce a list of strings:
=begin sidebar
-Perl will produce a warning if the literal string contains a comma or the
-comment character.
+Perl will produce a warning if a C<qw()> contains a comma or the comment
+character (C<#>), because not only are such characters rarely included in a
+C<qw()>, their presence usually indicates an oversight.
=end sidebar
View
@@ -17,7 +17,7 @@ X<variables; names>
Not all variables require names, but most of the variables you will encounter
in your programs will have names. Variables in Perl 5 must conform to the
-standard rules of identifier naming (L<names>). Varibles also have leading
+standard rules of identifier naming (L<names>). Variables also have leading
sigils.
=head3 Variable Scopes

0 comments on commit 5c596e6

Please sign in to comment.