Skip to content

Commit

Permalink
Improved line and pagebreaking for chapter 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
chromatic committed Dec 5, 2011
1 parent 6fbd05f commit 6b72ad7
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 244 deletions.
30 changes: 13 additions & 17 deletions sections/arrays.pod
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Assign to individual positions in an array directly by index:
$cats[0] = 'Daisy';
$cats[1] = 'Petunia';
$cats[4] = 'Brad';
$cats[5] = 'Choco';

=end programlisting

Expand All @@ -127,17 +128,13 @@ As an assignment shortcut, initialize an array from a list:

=begin programlisting

my @cats = ( 'Daisy', 'Petunia', 'Tuxedo', 'Jack', 'Brad' );
my @cats = ( 'Daisy', 'Petunia', 'Tuxedo', ... );

=end programlisting

=begin sidebar

Remember that these parentheses I<do not> create a list. Without parentheses,
this would assign C<Daisy> as the first and only element of the array, due to
operator precedence (L<precedence>).

=end sidebar
... but remember that these parentheses I<do not> create a list. Without
parentheses, this would assign C<Daisy> as the first and only element of the
array, due to operator precedence (L<precedence>).

Any expression which produces a list in list context can assign to an array:

Expand Down Expand Up @@ -217,7 +214,7 @@ slice evaluated in scalar context will produce a warning:

=begin screen

Scalar value @cats[1] better written as $cats[1] at...
Scalar value @cats[1] better written as $cats[1]...

=end screen

Expand Down Expand Up @@ -281,7 +278,7 @@ the start of an array, respectively:
=begin programlisting

# expand our culinary horizons
unshift @meals, qw( tofu curry spanakopita taquitos );
unshift @meals, qw( tofu spanakopita taquitos );

# rethink that whole soy idea
shift @meals;
Expand All @@ -292,12 +289,8 @@ C<unshift> prepends a list of elements to the start of the array and returns
the new number of elements in the array. C<shift> removes and returns the first
element of the array.

=begin tip Zero, One, or Many

Few programs use the return values of C<push> and C<unshift>.

=end tip

X<arrays; C<splice>>
X<builtins; C<splice>>

Expand Down Expand Up @@ -367,7 +360,9 @@ nested arrays in Perl 5:
=begin programlisting

# creates a single array, not an array of arrays
my @array_of_arrays = ( 1 .. 10, ( 11 .. 20, ( 21 .. 30 ) ) );
my @numbers = ( 1 .. 10,
( 11 .. 20,
( 21 .. 30 ) ) );

=end programlisting

Expand All @@ -376,7 +371,7 @@ nested arrays in Perl 5:
=begin programlisting

# creates a single array, not an array of arrays
my @array_of_arrays = 1 .. 30;
my @numbers = 1 .. 30;

=end programlisting

Expand All @@ -400,7 +395,8 @@ C<$LIST_SEPARATOR>. Thus:

my @alphabet = 'a' .. 'z';
say "[@alphabet]";
B<[a b c d e f g h i j k l m n o p q r s t u v w x y z]>
B<[a b c d e f g h i j k l m>
B<n o p q r s t u v w x y z]>

=end programlisting

Expand Down
6 changes: 3 additions & 3 deletions sections/coercion.pod
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ manipulating nested data structures (L<nested_data_structures>):

my %users;

$users{Bradley}{id} = 228;
$users{Jack}{id} = 229;
$users{Brad}{id} = 228;
$users{Jack}{id} = 229;

=end programlisting

Although the hash never contained values for C<Bradley> and C<Jack>, Perl
Although the hash never contained values for C<Brad> and C<Jack>, Perl
helpfully created hash references for them, then assigned each a key/value pair
keyed on C<id>.

Expand Down
Loading

0 comments on commit 6b72ad7

Please sign in to comment.