Mastering Algorithms with Perl

( 1 )


Many programmers would love to use Perl for projects that involve heavy lifting, but miss the many traditional algorithms that textbooks teach for other languages. Computer scientists have identified many techniques that a wide range of programs need, such as:

  • Fuzzy pattern matching for text (identify misspellings!)
  • Finding correlations in ...
See more details below
Other sellers (Paperback)
  • All (21) from $1.99   
  • New (8) from $18.62   
  • Used (13) from $1.99   
Mastering Algorithms with Perl

Available on NOOK devices and apps  
  • NOOK Devices
  • Samsung Galaxy Tab 4 NOOK 7.0
  • Samsung Galaxy Tab 4 NOOK 10.1
  • NOOK HD Tablet
  • NOOK HD+ Tablet
  • NOOK eReaders
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac
  • NOOK for Web

Want a NOOK? Explore Now

NOOK Book (eBook)
$17.99 price
(Save 43%)$31.99 List Price


Many programmers would love to use Perl for projects that involve heavy lifting, but miss the many traditional algorithms that textbooks teach for other languages. Computer scientists have identified many techniques that a wide range of programs need, such as:

  • Fuzzy pattern matching for text (identify misspellings!)
  • Finding correlations in data
  • Game-playing algorithms
  • Predicting phenomena such as Web traffic
  • Polynomial and spline fitting
Using algorithms explained in this book, you too can carry out traditional programming tasks in a high-powered, efficient, easy-to-maintain manner with Perl.This book assumes a basic understanding of Perl syntax and functions, but not necessarily any background in computer science. The authors explain in a readable fashion the reasons for using various classic programming techniques, the kind of applications that use them, and — most important — how to code these algorithms in Perl.If you are an amateur programmer, this book will fill you in on the essential algorithms you need to solve problems like an expert. If you have already learned algorithms in other languages, you will be surprised at how much different (and often easier) it is to implement them in Perl. And yes, the book even has the obligatory fractal display program.There have been dozens of books on programming algorithms, some of them excellent, but never before has there been one that uses Perl.The authors include the editor of The Perl Journal and master librarian of CPAN; all are contributors to CPAN and have archived much of the code in this book there."This book was so exciting I lost sleep reading it." Tom Christiansen

This part algorithm-textbook, part how-to-manual is loaded with valuable information for programmers. It falls somewhere between advanced Perl concepts and the classic computer science text on algorithms; it provides a detailed practical analysis, not a rigorous exposition of algorithmic theory. For this advanced guide, you should understand Perl and programming basics.

Read More Show Less

Editorial Reviews

Library Journal
Perl is very similar to C in syntax, and while Perl doesn't have the speed of complied C, it has been getting much faster. It also is one of the most portable languages, available for most hardware with no changes in code. It is free, which makes it very attractive to developers. This guide covers everything from data structures, sorting and searching, to sets and matrices, to cryptography, probability, and statistics. Readers must already know Perl, so this is recommended for advanced programming collections. Copyright 1999 Cahners Business Information.
Read More Show Less

Product Details

  • ISBN-13: 9781565923980
  • Publisher: O'Reilly Media, Incorporated
  • Publication date: 8/1/1999
  • Edition number: 1
  • Pages: 706
  • Sales rank: 1,076,804
  • Product dimensions: 7.06 (w) x 9.19 (h) x 1.29 (d)

Meet the Author

Jarkko Hietaniemi is the creator and Master Librarian of CPAN: Comprehensive Perl Archive Network. He has also been known to frequent Perl developer forums. Luckily enough, getting his MSc in CS in the field of parallel computing didn't interfere overly much with his Perl and UNIX hacking. During those savored moments of off-line time, he fancies gobbling up speculative fiction and popular science. His real life employer is Nokia Research Center.

John Macdonald has been using Perl commercially since 1988 for a suite of Unix system administration tools. His background with Unix dates back to the days when Unix was written in PDP-11 assembler and later includes representing the University of Waterloo at the first UNIX Users Meeting at City University of New York in the mid-1970s while finishing his M. Math degree. (In those days before the creation of Usenix, the people at the meeting would sit together around a single table.) In addition, his background includes work on compilers, kernel internals, device drivers and the like. He has also been observed partaking in recreational computing activities.

Jon Orwant, a well-known member of the Perl community, founded The Perl Journal and co-authored OReillys bestseller, Programming Perl, 3rd Edition.

Read More Show Less

Table of Contents


Chapter 1: Introduction

Chapter 2: Basic Data Structures

Chapter 3: Advanced Data Structures

Chapter 4: Sorting

Chapter 5: Searching

Chapter 6: Sets

Chapter 7: Matrices

Chapter 8: Graphs

Chapter 9: Strings

Chapter 10: Geometric Algorithms

Chapter 11: Number Systems

Chapter 12: Number Theory

Chapter 13: Cryptography

Chapter 14: Probability

Chapter 15: Statistics

Chapter 16: Numerical Analysis

Further Reading

ASCII Character Set


Read More Show Less


Perl's popularity has soared in recent years. It owes its appeal first to its technical superiority: Perl's unparalleled portability, speed, and expressiveness have made it the language of choice for a million programmers worldwide.

Those programmers have extended Perl in ways unimaginable with languages controlled by committees or companies. Of all languages, Perl has the largest base of free utilities, thanks to the Comprehensive Perl Archive Network (abbreviated CPAN; see The modules and scripts you'll find there have made Perl the most popular language for web, text, and database programming.

But Perl can do more than that. You can solve complexproblemss in Perl more quickly, and in fewer lines, than in any other language.

This ease of use makes Perl an excellent tool for exploring algorithms. Computer science embraces complexity; the essence of programming is the clean dissection of a seemingly insurmountable problem into a series of simple, computable steps Perl is ideal for tackling the tougher nuggets of computer science because its liberal syntax lets the programmer express his or her solution in the manner best suited to the task. (After all, Perl's motto is There's More Than One Way To Do It.) Algorithms are complex enough; we don't need a computer language making it any tougher.

Most books about computer algorithms don't include working programs. They express their ideas in quasi-English pseudocode instead, which allows the discussion to focus on concepts without getting bogged down in implementation details. But sometimes the details are what matter -- the inefficiencies of a bad implementation sometimes cancel the speedupthat a good algorithm provides. The devil is in the details.

And while converting ideas to programs is often a good exercise, it's also just plain time-consuming. So, in this book we've supplied you with not just explanations, but implementations as well, If you read this book carefully, you'll learn more about both algorithms and Perl.

About This Book

This book is written for two kinds of people: those who want cut and paste solutions and those who want to hone their programming skills. You'11 see how we solve some of the classic problems of computer science and why we solved them the way we did.

Theory or Practice?

Like the wolf featured on the cover, this book is sometimes fierce and sometimes playful. The fierce part is the computer science: we'll often talk like computer scientists talk and discuss problems that matter little to the practical Perl programmer. Other times, we'll playfully explain the problem and simply tell you about ready-made solutions you can find on the Internet (almost always on CPAN).

Deciding when to be fierce and when to be playful hasn't been easy for us. For instance, every algorithms textbook has a chapter on all of the different ways to sort a collection of items. So do we, even though Perl provides its own sort() function that might be all you ever need. We do this for four reasons. First, we don't want you thinking you've Mastered Algorithms without understanding the algorithms covered in every college course on the subject. Second, the concepts, processes, and strategies underlying those algorithms will come in handy for more than just sorting, Third, it helps to know how Perl's sort() works under the hood, why its particular algorithm (quicksort) was used, and how to avoid some of the inefficiencies that even experienced Perl programmers fall prey to. Finally, sort() isn't always the best solution! Someday, you might need another of the techniques we provide.

When it comes to the inevitable tradeoffs between theory and practice, programmers' tastes vary. We have chosen a middle course, swiftly pouncing from one to the other with feral abandon. If your tastes are exclusively theoretical or practical, we hope you'll still appreciate the balanced diet you'll find here.

Organization of This Book

The chapters in this book can be read in isolation; they typically don't require knowledge from previous chapters. However, we do recommend that you read at least Chapter 1, Introduction, and Chapter 2, Basic Data Structures, which provide the basic material necessary for understanding the rest of the book.

Chapter 1 describes the basics of Perl and algorithms, with an emphasis on speed and general problem-solving techniques.

Chapter 2 explains how to use Perl to create simple and very general representations, like queues and lists of lists.

Chapter 3, Advanced Data Structures, shows how to build the classic computer science data structures.

Chapter 4, Sorting, looks at techniques for ordering data and compares the advantages of each technique.

Chapter 5, Searching, investigates ways to extract individual pieces of information from a larger collection.

Chapter 6, Sets, discusses the basics of set theory and Perl implementations of set operations.

Chapter 7, Matrices, examines techniques for manipulating large arrays of data and solving problems in linear algebra.

Chapter 8, Graphs, describes tools for solving problems that are best represented as a graph a collection of nodes connected by edges.

Chapter 9, Strings, explains how to implement algorithms for searching, filtering, and parsing strings of text.

Chapter 10, Geometric Algorithms, looks at techniques for computing with two- and three-dimensional constructs.

Chapter 11, Number Systems, investigates methods for generating important constants, functions, and number series, as well as manipulating numbers in alternate coordinate systems.

Chapter 12, Number Theory, examines algorithms for factoring numbers, modular arithmetic, and other techniques for computing with integers.

Chapter 13, Cryptography, demonstrates Perl utilities to conceal your data from prying eyes.

Chapter 14, Probability, discusses how to use Perl for problems involving chance.

Chapter 15, Statistics, describes methods for analyzing the accuracy of hypotheses and characterizing the distribution of data.

Chapter 16, Numerical Analysis, looks at a few of the more common problems in scientific computing.

Appendix A, Further Reading, contains an annotated bibliography.

Appendix B, ASCII Character Set, lists the seven-bit ASCII character set used by default when Perl sorts strings.

Conventions Used in This Book

Used for filenames, directory names, URLs, and occasional emphasis.

Constant width
Used for elements of programming languages, text manipulated by programs, code examples, and output.

Constant width bold
Used for user input and for emphasis in code.

Constant width italic
Used for replaceable values.

What You Should Know Before Reading This Book

Algorithms are typically the subject of an entire upper-level undergraduate course in computer science departments. Obviously, we cannot hope to provide all of the mathematical and programming background you'll need to get the most out of this book. We believe that the best way to teach is never to coddle, but to explain complex concepts in an entertaining fashion and thoroughly ground them in applications whenever possible. You don't need to be a computer scientist to read this book, but once you've read it you might feel justified calling yourself one.

That said, if you don't know Perl, you don't want to start here. We recommend you begin with either of these books published by O'Reilly & Associates: Randal L. Schwartz and Tom Christiansen's Learning Perl if you're new to programming, and Larry Wall, Tom Christiansen, and Randal L. Schwartz's Programming Perl if you're not.

If you want more rigorous explanations of the algorithms discussed in this book, we recommend either Thomas H. Cormen, Charles E. Leiserson, and Ronald L. Rivest's Introduction to Algorithms, published by MIT Press, or Donald Knuth's The Art of Computer Programming, Volume I (Fundamental Algorithms) in particular. See Appendix A for full bibliographic information.

What You Should Have Before Reading This Book

This book assumes you have Perl 5.004 or better. If you don't, you can download it for free from

This book often refers to CPAN modules, which are packages of Perl code you can download for free from In particular, the module ( can automatically download, build, and install CPAN modules for you.

Typically, the modules in CPAN are usually quite robust because they're tested and used by large user populations. You can check the Modules List (reachable by a link from to see how authors rate their modules; as a module rating moves through "idea," "under construction," "alpha," "beta," and finally to "Released," there is an increasing likelihood that it will behave properly.

Online Information About This Book

All of the programs in this book are available online from, in the directory /pub/examples/perl/algorithms/examples.tar.gz. If we learn of any errors in this book, you'll be able to find them at /pub/examples/perl/algorithms/errata.txt. ...
Read More Show Less

Customer Reviews

Average Rating 4
( 1 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing 1 Customer Reviews
  • Anonymous

    Posted September 15, 2011

    No text was provided for this review.

Sort by: Showing 1 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)