Permalink
Browse files

allineato con repo chromatic subito dopo DEADLINE3

  • Loading branch information...
1 parent 5dd6305 commit 0b0c35adf536693bec9bcb7eaeebee96a6120a0e @giatorta giatorta committed Jan 20, 2012
View
@@ -1,35 +1,35 @@
-\chapter*{}
\thispagestyle{empty}
-\huge{Modern Perl}
+\huge{\booktitle}
\newline
-\large{2011 - 2012 edition}
+\large{\booksubtitle}
\newline
\newline
\normalsize
-Copyright \copyright~2010-2011 chromatic
+Copyright \copyright~2010-2012 \bookauthor
\vfill
\textbf{Editor:} Shane Warden\newline
\textbf{Logo design:} Devin Muldoon\newline
-\textbf{Cover design:} Allison Randal and chromatic
+\textbf{Cover design:} Allison Randal, chromatic, and Jeffrey Martin
-\textbf{ISBN-10:} 0-9779201-5-1\newline
-\textbf{ISBN-13:} 978-0-9779201-5-0
+\textbf{ISBN-10:} \bookisbnten\newline
+\textbf{ISBN-13:} \bookisbnthirteen
Published by Onyx Neon Press, \url{http://www.onyxneon.com/}.
The Onyx Neon logo is a trademark of Onyx Neon, Inc.
-This book was typeset on Ubuntu GNU/Linux using Perl 5,
-\textnhtt{Pod::PseudoPod::LaTeX}, and \LaTeX. Many thanks to the free software
-contributors who make these and other projects possible.
-
-This is a draft of a work in progress, rendered on \today. Please do not
-redistribute this book. Please \emph{do} report any errors of content (not
-formatting) at \url{http://github.com/chromatic/modern_perl_book/}.
+Onyx Neon typesets books with free software, especially Ubuntu GNU/Linux, Perl
+5, PseudoPod, and \LaTeX. Many thanks to the contributors who make these and
+other projects possible.
2010 - 2011 Edition October 2010\newline
-2011 - 2012 Edition October 2011
+2011 - 2012 Edition January 2012
+
+Electronic versions of this book are available from
+\url{http://onyxneon.com/books/modern_perl/}, and the companion website is
+\url{http://modernperlbooks.com/}. Please share with your friends and
+colleagues.
Thanks for reading!
@@ -0,0 +1,5 @@
+\newcommand{\booktitle}{Modern Perl}
+\newcommand{\booksubtitle}{2011-2012 edition}
+\newcommand{\bookauthor}{chromatic}
+\newcommand{\bookisbnten}{0-9779201-7-8}
+\newcommand{\bookisbnthirteen}{978-0-9779201-7-4}
View
@@ -21,10 +21,9 @@ with code declared elsewhere?
X<OO; is-a>
X<OO; has-a>
-Inheritance is but one of many tools. Although C<Car> may extend
-C<Vehicle::Wheeled> (an I<is-a relationship>), it's likely better for C<Car> to
-I<contain> contain several C<Wheel> objects as instance attributes (a I<has-a
-relationship>).
+Inheritance is but one of many tools. A C<Car> may extend C<Vehicle::Wheeled>
+(an I<is-a relationship>), but C<Car> may better I<contain> several C<Wheel>
+objects as instance attributes (a I<has-a relationship>).
Decomposing complex classes into smaller, focused entities (whether classes or
roles) improves encapsulation and reduces the possibility that any one class or
@@ -99,8 +99,11 @@ You may also see anonymous functions passed as function arguments:
X<anonymous functions; names>
+X<CPAN; C<Sub::Identify>>
+
Given a reference to a function, you can determine whether the function is
-named or anonymous with introspection:
+named or anonymous with introspectionN<... or C<sub_name> from the CPAN module
+C<Sub::Identify>.>:
=begin programlisting
@@ -123,15 +126,6 @@ named or anonymous with introspection:
=end programlisting
-=begin tip Who Are You?
-
-X<CPAN; C<Sub::Identify>>
-
-The CPAN module C<Sub::Identify>'s C<sub_name> function simplifies this
-introspection.
-
-=end tip
-
The result may be surprising:
Called from ShowCaller::B<main>
@@ -183,7 +177,10 @@ Perl 5 allows the declaration of anonymous functions implicitly through the use
of prototypes (L<prototypes>). Though this feature exists nominally to enable
programmers to write their own syntax such as that for C<map> and C<eval>, an
interesting example is the use of I<delayed> functions that don't look like
-functions. Consider the CPAN module C<Test::Fatal>:
+functions.
+
+Consider the CPAN module C<Test::Fatal>, which takes an anonymous function as
+the first argument to its C<exception()> function:
=begin programlisting
@@ -200,8 +197,7 @@ functions. Consider the CPAN module C<Test::Fatal>:
=end programlisting
-The function C<exception()> takes an anonymous function as its first argument.
-These calls are equivalent to:
+You might rewrite this more verbosely as:
=begin programlisting
@@ -210,9 +206,7 @@ These calls are equivalent to:
=end programlisting
-... but are easier to read.
-
-This syntax allows you to pass named functions by reference as well:
+... or to pass named functions by reference:
=begin programlisting
View
@@ -1,17 +1,15 @@
=head1 Arrays
Z<arrays>
+
X<arrays>
+X<C<@> sigil>
+X<sigils; C<@>>
Perl 5 I<arrays> are I<first-class> data structures--the language supports them
as a built-in data type--which store zero or more scalars. You can access
individual members of the array by integer indexes, and you can add or remove
-elements at will.
-
-X<C<@> sigil>
-X<sigils; C<@>>
-
-The C<@> sigil denotes an array. To declare an array:
+elements at will. The C<@> sigil denotes an array. To declare an array:
=begin programlisting
@@ -58,37 +56,27 @@ addition, or boolean context) evaluates to the number of elements in the array:
=end programlisting
-To get the I<index> of the final element of an array, subtract one from the
-number of elements of the array (remember that array indexes start at 0):
-
-=begin programlisting
-
- my $first_index = 0;
- my $last_index = @cats - 1;
-
- say "My first cat has an index of $first_index, "
- . "and my last cat has an index of $last_index."
-
-=end programlisting
-
X<C<$#>; sigil>
X<sigils; C<$#>>
-The less wieldy syntax C<$#cats> also evaluates to the last index of the array:
+To get the I<index> of the final element of an array, subtract one from the
+number of elements of the array (remember that array indexes start at 0) or use the unwieldy C<$#cats> syntax:
=begin programlisting
my $first_index = 0;
- B<my $last_index = $#cats;>
+ my $last_index = @cats - 1;
+ # or
+ # my $last_index = $#cats;
say "My first cat has an index of $first_index, "
. "and my last cat has an index of $last_index."
=end programlisting
-... though it's often clearer to use negative array indices instead. The last
-element of an array is available at the index C<-1>. The second to last element
-of the array is available at index C<-2>, and so on:
+When the index matters less than the position of an element, use negative array
+indices instead. The last element of an array is available at the index C<-1>.
+The second to last element of the array is available at index C<-2>, and so on:
=begin programlisting
@@ -166,68 +154,6 @@ freshly-declared arrays start out empty.
=end tip
-=head2 Array Slices
-
-Z<array_slices>
-
-X<arrays; slices>
-X<slices; array>
-X<C<@>; sigil>
-X<sigils; C<@>>
-
-The I<array slice> construct allows you to access elements of an array in list
-context. Unlike scalar access of an array element, this indexing operation
-takes a list of zero or more indices and uses the array sigil (C<@>):
-
-=begin programlisting
-
- my @youngest_cats = @cats[-1, -2];
- my @oldest_cats = @cats[0 .. 2];
- my @selected_cats = @cats[ @indexes ];
-
-=end programlisting
-
-Array slices are useful for assignment:
-
-=begin programlisting
-
- @users[ @replace_indices ] = @replace_users;
-
-=end programlisting
-
-A slice can contain zero or more elements--including one:
-
-=begin programlisting
-
- # single-element array slice; function call in I<list> context
- @cats[-1] = get_more_cats();
-
- # single-element array access; function call in I<scalar> context
- $cats[-1] = get_more_cats();
-
-=end programlisting
-
-The only syntactic difference between an array slice of one element and the
-scalar access of an array element is the leading sigil. The I<semantic>
-difference is greater: an array slice always imposes list context. An array
-slice evaluated in scalar context will produce a warning:
-
-=begin screen
-
- Scalar value @cats[1] better written as $cats[1]...
-
-=end screen
-
-An array slice imposes list context (L<context_philosophy>) on the expression
-used as its index:
-
-=begin programlisting
-
- # function called in list context
- my @hungry_cats = @cats[ get_cat_indices() ];
-
-=end programlisting
-
=head2 Array Operations
Sometimes an array is more convenient as an ordered, mutable collection of
@@ -326,6 +252,67 @@ As of Perl 5.12, C<each> can iterate over an array by index and value:
=end programlisting
+=head2 Array Slices
+
+Z<array_slices>
+
+X<arrays; slices>
+X<slices; array>
+X<C<@>; sigil>
+X<sigils; C<@>>
+
+The I<array slice> construct allows you to access elements of an array in list
+context. Unlike scalar access of an array element, this indexing operation
+takes a list of zero or more indices and uses the array sigil (C<@>):
+
+=begin programlisting
+
+ my @youngest_cats = @cats[-1, -2];
+ my @oldest_cats = @cats[0 .. 2];
+ my @selected_cats = @cats[ @indexes ];
+
+=end programlisting
+
+Array slices are useful for assignment:
+
+=begin programlisting
+
+ @users[ @replace_indices ] = @replace_users;
+
+=end programlisting
+
+A slice can contain zero or more elements--including one:
+
+=begin programlisting
+
+ # single-element array slice; I<list> context
+ @cats[-1] = get_more_cats();
+
+ # single-element array access; I<scalar> context
+ $cats[-1] = get_more_cats();
+
+=end programlisting
+
+The only syntactic difference between an array slice of one element and the
+scalar access of an array element is the leading sigil. The I<semantic>
+difference is greater: an array slice always imposes list context. An array
+slice evaluated in scalar context will produce a warning:
+
+=begin screen
+
+ Scalar value @cats[1] better written as $cats[1]...
+
+=end screen
+
+An array slice imposes list context on the expression used as its index:
+
+=begin programlisting
+
+ # function called in list context
+ my @hungry_cats = @cats[ get_cat_indices() ];
+
+=end programlisting
+
=head2 Arrays and Context
X<list context; arrays>
@@ -400,24 +387,13 @@ C<$LIST_SEPARATOR>. Thus:
=end programlisting
-Temporarily localizing and assigning another value to C<$"> for debugging
-purposes is very handyN<Credit goes to Mark Jason Dominus for demonstrating its
-efficacy.>:
+Localize C<$"> with a delimiter to ease your debuggingN<Credit goes to Mark Jason Dominus for this technique.>:
=begin programlisting
# what's in this array again?
- {
- local $" = ')(';
- say "(@sweet_treats)";
- }
+ local $" = ')(';
+ say "(@sweet_treats)";
+ B<(pie)(cake)(doughnuts)(cookies)(raisin bread)>
=end programlisting
-
-... which produces the result:
-
-=begin screen
-
- (pie)(cake)(doughnuts)(cookies)(raisin bread)
-
-=end screen
View
@@ -36,11 +36,9 @@ CPAN uses such parametric arguments to good effect:
=begin programlisting
- sub setup_tests :Test(setup) { ... }
-
- sub test_monkey_creation :Test(10) { ... }
-
- sub shutdown_tests :Test(teardown) { ... }
+ sub setup_tests :Test(setup) { ... }
+ sub test_monkey_creation :Test(10) { ... }
+ sub shutdown_tests :Test(teardown) { ... }
=end programlisting
Oops, something went wrong.

0 comments on commit 0b0c35a

Please sign in to comment.