*Preface

Perl turns 23 years old later this year. The language has gone from a simple tool for system administration somewhere between shell scripting and C programming (Perl 1) to a powerful, general-purpose language steeped in a rich heritage (Perl 5) and a consistent, coherent, rethinking of programming in general intended to last for another 25 years (Perl 6).

Even so, most Perl 5 programs in the world take far too little advantage of the language. You can write Perl 5 programs as if they were Perl 4 programs (or Perl 3 or 2 or 1), but programs written to take advantage of everything amazing the worldwide Perl 5 community has invented, polished, and discovered are shorter, faster, more powerful, and easier to maintain than their alternatives.

Modern Perl is a loose description of how experienced and effective Perl 5 programmers work. They use language idioms. They take advantage of the CPAN. They're recognizably Perlish, and they show good taste and craftsmanship and a full understanding of Perl.

You can learn this too.

Running Modern Perl

Unless otherwise mentioned, code snippets always assume the basic skeleton of a program:

    #!/usr/bin/perl

    use Modern::Perl;

    # example code here
    ...

Other code snippets use testing functions such as ok(), like(), and is() (Testing). That skeleton program is:

    #!/usr/bin/perl

    use Modern::Perl;
    use Test::More;

    # example code here
    ...
    done_testing();

The examples in this book work best with Perl 5.10.0 or newer; ideally at least Perl 5.10.1. Many examples will work on older versions of Perl 5 with modest changes, but you will have more difficulty with anything older than 5.10.0. This book also describes (but does not require the use of) features found in Perl 5.12.

You can often install a new version of Perl yourself. Windows users, download Strawberry Perl from http://www.strawberryperl.com/. Users of other operating systems with Perl 5 already installed (and a C compiler and the other development tools), start by installing the CPAN module App::perlbrew (footnote: See http://search.cpan.org/perldoc?App::perlbrew for installation instructions.).

perlbrew allows you to install and to manage multiple versions of Perl 5. By default, it installs them to your own home directory. Not only can you have multiple versions of Perl 5 installed without affecting the system Perl but you can also install any module you like into these directories without asking your system administrator for specific permission.

Perl 5 and Perl 6

Should you learn Perl 5 or Perl 6? They share philosophy and syntax and libraries and community; they fill different niches. Learn Perl 5 if:

Learn Perl 6 if:

In general, Perl 5 development is conservative with regard to the core language. For good or for ill, change occurs slowly. Perl 6 is more experimental, as it considers finding the best possible design more important than keeping old code working. Fortunately, you can learn and use both languages (and they interoperate to an ever-improving degree).

This book discusses Perl 5. To learn more about Perl 6, see http://perl6.org/, try Rakudo (http://www.rakudo.org/), and refer to the book Using Perl 6, also published by Onyx Neon Press.

Credits

This book would not have been possible in its current form without questions, comments, suggestions, advice, wisdom, and encouragement from many, many people. In particular, the author and editor would like to thank:

John SJ Anderson, Peter Aronoff, Lee Aylward, Alex Balhatchet, Ævar Arnfjörð Bjarmason, Matthias Bloch, John Bokma, Vasily Chekalkin, Dmitry Chestnykh, E. Choroba, Paulo Custodio, Felipe, Shlomi Fish, Jeremiah Foster, Mark Fowler, John Gabriele, Andrew Grangaard, Bruce Gray, Ask Bjørn Hansen, Tim Heaney, Robert Hicks, Michael Hind, Mark Hindess, Yary Hluchan, Mike Huffman, Curtis Jewell, Mohammed Arafat Kamaal, James E Keenan, Yuval Kogman, Jan Krynicky, Jeff Lavallee, Moritz Lenz, Jean-Baptiste Mazon, Josh McAdams, Gareth McCaughan, John McNamara, Shawn M Moore, Alex Muntada, Carl Mäsak, Chris Niswander, Nelo Onyiah, Chas. Owens, ww from PerlMonks, Jess Robinson, Dave Rolsky, Gabrielle Roth, Andrew Savige, Lorne Schachter, Dan Scott, Alexander Scott-Johns, Phillip Smith, Christopher E. Stith, Mark A. Stratman, Bryan Summersett, Audrey Tang, Scott Thomson, Ben Tilly, Sam Vilain, Larry Wall, Colin Wetherbee, Frank Wiegand, Doug Wilson, Sawyer X, David Yingling, Marko Zagozen, harleypig, hbm, and sunnavy.

Any errors are the fault of the author's own stubbornness.