Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved line and pagebreaking for chapter 10.

  • Loading branch information...
commit 3cabfec37565b7c35ff31df7e2ac17ce129e920f 1 parent 5e958de
@chromatic authored
Showing with 24 additions and 34 deletions.
  1. +2 −10 sections/globals.pod
  2. +22 −24 sections/idioms.pod
View
12 sections/globals.pod
@@ -28,7 +28,7 @@ right approach:
=begin programlisting
- my $file = do { B<local $/> = <$fh> };
+ my $file; { B<local $/>; $file = <$fh> };
=end programlisting
@@ -60,15 +60,7 @@ lexicals that have gone out of scope may reset C<$@>:
=end programlisting
Copy C<$@> I<immediately> after catching an exception to preserve its contents.
-
-=begin tip Safer Exception Handling
-
-X<CPAN; C<Try::Tiny>>
-
-While Perl 5.14 has fixed some odd bugs related to exception handling,
-C<Try::Tiny> is still the most reliable mechanism to catch exceptions.
-
-=end tip
+See also C<Try::Tiny> instead (L<exception_caveats>).
=head2 English Names
View
46 sections/idioms.pod
@@ -63,7 +63,7 @@ if it were a single argument:
{
B<my %args = @_;>
- my $ice_cream = get_ice_cream( $args{ice_cream} );
+ my $dessert = get_ice_cream( $args{ice_cream} );
...
}
@@ -146,7 +146,8 @@ fashion--in this case, two-element anonymous arrays:
=begin programlisting
- my @pairs = map { [ $_, $extensions{$_} ] } keys %extensions;
+ my @pairs = map { [ $_, $extensions{$_} ] }
+ keys %extensions;
=end programlisting
@@ -162,7 +163,8 @@ C<sort> takes the list of anonymous arrays and compares their second elements
=begin programlisting
- my @sorted_pairs = sort { $a->[1] cmp $b->[1] } @pairs;
+ my @sorted_pairs = sort { $a->[1] cmp $b->[1] }
+ @pairs;
=end programlisting
@@ -190,7 +192,8 @@ to a more usable form:
=begin programlisting
- my @formatted_exts = map { "$_->[1], ext. $_->[0]" } @sorted_pairs;
+ my @formatted_exts = map { "$_->[1], ext. $_->[0]" }
+ @sorted_pairs;
=end programlisting
@@ -249,11 +252,9 @@ files into a scalar in a single expression:
my $file = do { local $/ = <$fh> };
# or
-
my $file = do { local $/; <$fh> };
# or
-
my $file; { local $/; $file = <$fh> };
=end programlisting
@@ -322,10 +323,8 @@ Z<controlled_execution>
The effective difference between a program and a module is in its intended use.
Users invoke programs directly, while programs load modules after execution has
-already begun. Yet a module is Perl code, just like a program except for how
-you run it.
-
-Making a module executable is easy. So is making a program behave as a module
+already begun. Yet a module is Perl code, in the same way that a program is.
+Making a module executable is easy. So is making a program behave as a module
(useful for testing parts of an existing program without formally making a
module). All you need to do is to discover I<how> Perl began to execute a piece
of code.
@@ -371,15 +370,14 @@ write:
=begin programlisting
- use Carp;
+ use Carp 'croak';
sub groom_monkeys
{
if (@_ != 2)
{
- croak 'Monkey grooming requires two monkeys!';
+ croak 'Grooming requires two monkeys!';
}
-
...
}
@@ -390,7 +388,7 @@ the check and deserve to be at the I<start> of the expression:
=begin programlisting
- croak 'Monkey grooming requires two monkeys!' if @_ != 2;
+ croak 'Grooming requires two monkeys!' if @_ != 2;
=end programlisting
@@ -398,7 +396,8 @@ the check and deserve to be at the I<start> of the expression:
=begin programlisting
- croak 'Monkey grooming requires two monkeys!' unless @_ == 2;
+ croak 'Grooming requires two monkeys!'
+ unless @_ == 2;
=end programlisting
@@ -413,8 +412,7 @@ Z<regex_en_passant>
X<regex; modification>
X<regex; substitution>
-Many Perl 5 idioms rely on the language design where expressions evaluate to
-values, as in:
+Many Perl 5 idioms rely on the fact that expressions evaluate to values:
=begin programlisting
@@ -450,6 +448,13 @@ user name for a system account, you could write:
=end programlisting
+=begin tip /r in Perl 5.14
+
+Perl 5.14 added the non-destructive substitution modifier C</r>, so that you
+can write C<my $normalized_name = $name =~ tr/A-Za-z//dcB<r>;>.
+
+=end tip
+
First, assign the value of C<$name> to C<$normalized_name>, as the parentheses
affect the precedence so that assignment happens first. The assignment
expression evaluates to the I<variable> C<$normalized_name>, so that that
@@ -466,13 +471,6 @@ This technique works on other in-place modification operators:
=end programlisting
-=begin tip /r in Perl 5.14
-
-Perl 5.14 added the non-destructive substitution modifier C</r>, so that you
-can write C<my $normalized_name = $name =~ tr/A-Za-z//dcB<r>;>.
-
-=end tip
-
=head2 Unary Coercions
Z<unary_coercions>
Please sign in to comment.
Something went wrong with that request. Please try again.