Forgot your password?
Book Reviews Books Media

Minimal Perl for Unix and Linux People 332

Posted by samzenpus
from the easy-does-it dept.
Ravi writes "Perl (Practical Extraction and Report Language) — the language which was created by Larry Wall is arguably one of the greatest programming languages. But it has a reputation for taking an excessive cryptic nature which gives it an image especially among Perl novices as a language which is complex and hard to master. Minimal Perl: for Unix and Linux people, authored by Tim Maher and published by Manning Publications addresses the obstacles presented by Perl's complexity. This book which is divided into two parts comprising of a total of 12 chapters takes a unique methodology to explain the Perl syntax and its use. The author emphasizes on Perl's grep, awk and sed like features and relys on concepts such as inputs, filters and arguments to allow Unix users to directly apply their existing knowledge to the task of learning Perl." Read on for the rest of Ravi's review.
Minimal Perl for Unix and Linux People
author Tim Maher
pages 464
publisher Manning Publications
rating 8
reviewer Ravi
ISBN 1932394508
summary Provides a slice of Perl which when mastered can accomplish most of the jobs which require Perl
What I found while reading this book is that the "Minimal Perl" is a specially crafted subset of Perl language designed to be easily grasped by people who have a Unix background and who wish to use Perl to write their scripts. Its aim is to filter out the complex way of writing programs using Perl and whenever possible to accomplish tasks using just one or two lines of Perl. In the first part of the book, the author explains how Perl can be used to do the same tasks as accomplished by common Unix tools such as grep, awk, sed and find. He goes one step further by explaining how one can accomplish much more and in a much simpler way by using Perl techniques.

Throughout the book, the author makes sure that the learning curve in acquiring Perl skills remain gentle. Perl is a language whose syntax has a multitude of options, this book is peppered with numerous tables which provide excellent information at a glance. For example, in the third chapter titled "Perl as a (Better) grep command", the author lists and compares the fundamental capabilities of Perl and the different grep commands such as grep, egrep and fgrep which clearly shows the advantages that Perl has over grep. In another table, you get a birds eye view of the essential syntax of Perl's regular expressions and their meaning. This chapter alone has around 12 tables. This is a really nice feature because it doubles as a Perl reference where you can flip to the respective page and get the information you need.

The main strength and drawback of a language such as Perl is its dependence on regular expressions for accomplishing complex tasks. Once you master the regular expressions, the sky is the limit for ordering and segregating data using this language. In Perl, there is more than one way of doing the same thing. What is unique about this book is that the author specializes in explaining the easiest way of doing a particular task.

In many places, the author demonstrates complex tasks using just a few lines of Perl code. Many of the examples covered in this book are practical examples which give an idea of how the commands relate to the final outcome. For instance, while elaborating on the one line grep like commands in Perl, the author illustrates a web oriented application of pattern matching where he shows how to extract and list, the outline of site's front page. The surprising thing is this is accomplished using just a single line of Perl code. This book has lots of such one line examples which teache how to use Perl intelligently using minimal effort.

If part I of this book focuses on ways in which simple Perl programs can provide superior alternatives to standard Unix commands, the second part throws light on the other aspects of Perl concentrating on the syntax of the language and various built-in functions and modules available which do away with a lot of re-invention of the wheel, so to speak, and helps churn out code which is portable.

Chapter 7 titled "Built-in functions" introduces an eclectic mix of functions available in Perl. You have functions which are used to extract a list of fields from a string, functions to access the current date and time, generating random numbers, sorting lists, transforming lists, managing files with functions and so on. These functions are broadly classified into those which generate and process scalars and those that process lists.

In chapter 8 of this book, the author involves the reader on the numerous scripting techniques that can be used to write better Perl programs.

It was quite surprising that the author has chosen to discuss the variables, more specifically the list variables comprising of arrays and hashes, as well as the looping constructs only in the 9th and 10th chapters, when they should be somewhere up front. In hind sight, I feel it is a good decision. Once you execute the one liner Perl programs in the initial chapters, you will be fairly confident in using Perl by the time you reach the 9th chapter.

The last two chapters deal with creating sub-routines and modules. Over the years various Perl programmers have created modules which are used for diverse purposes. With an aim to share these modules, they are collected and stored at one central place known as CPAN, which is an acronym for Comprehensive Perl Archive Network. The final chapter, apart from teaching how to create modules in Perl and manage them, also introduces the CPAN and ways in which one can find the right module by searching on CPAN.

The special variables cheat-sheet and the guidelines for parenthesizing code provided in the two appendices are really useful as a quick reference while writing Perl programs.

This is not a comprehensive book on Perl, rather the author provides a slice of Perl which when mastered can accomplish most of the jobs which require Perl. You won't find object oriented concepts of Perl being mentioned in this book. In many ways the author has moved beyond explaining a subset of Perl by providing a section titled "Directions for further study" at the end of each chapter, where the author lists further material which can be used to learn more about the topic that is covered.

I really enjoyed going through this book, especially because of its focus on the practical side of using Perl and taking a minimal approach.

Ravi Kumar maintains a blog titled "All about Linux" where he shares his thoughts and experiences in using Linux, Open Source and Free software.

You can purchase Minimal Perl for Unix and Linux People from Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
This discussion has been archived. No new comments can be posted.

Minimal Perl for Unix and Linux People

Comments Filter:
  • Re:*sigh* (Score:3, Informative)

    by swordgeek (112599) on Wednesday February 21, 2007 @05:00PM (#18100870) Journal
    Honestly, it doesn't matter. The cart came before the horse in this case, but regardless of its acronymic meaning (or lack thereof) when it was created, Perl DOES now stand for Practical Extraction and Report Language. Just ask Larry Wall.
    Remeber that a "Backronym" (hate that word!) is a subtype of acronym.
  • by CRCulver (715279) <> on Wednesday February 21, 2007 @05:08PM (#18100978) Homepage

    I don't want to put Perl down, but I think that its day is past except for those who, because they learnt it when it was the only thing around, are willing to tolerate its eccentricities. While switching from sed/awk to a general-purpose programming language with good text manipulation abilities can certain improve the possibilities of what you can accomplish with a single chuck of code and processor (as opposed to the old-time Unix way of piping), I'd recommend Python for that, getting started with a guide like Mertz's Text Processing in Python [] (Addison-Wesley, 2003). Python is now as mature, if not more, in the realm of text processing as Perl was when its won its accolades a decade ago. (Heck, the treatment of Unicode is enormously forward-thinking compared to any other scripting language on the market.) And so you get the same power as you would with Perl, but much, much more readable.

    I fear I'm starting a holy war by recommending Python in a Perl discussion. That's certainly not my intention. For those who already know and love Perl I say, great, keep on trucking. But I just can't see the point in steering newbies towards it.

  • by Phreakiture (547094) on Wednesday February 21, 2007 @05:13PM (#18101062) Homepage

    Very useful if you need to use text files from DOS/Windows and DOX2UNIX is not installed:

    perl -e "while(<>){s/\r//;print;}"

    This strips carriage returns out of a file, and does it pretty quickly.

  • Re:Cryptic? (Score:4, Informative)

    by drinkypoo (153816) <> on Wednesday February 21, 2007 @05:21PM (#18101174) Homepage Journal

    Is it just me, or is it possible to create perfectly legible code in Perl if you use good technique, just like in any other language?

    Of course. The thing that people complain about is that perl allows you to write code that only a fellow perl-head can understand. It's harder to accomplish that with C, for example. But perl doesn't automatically mean you won't understand it. It just makes it more likely :)

  • Picking Up Perl (Score:5, Informative)

    by nbritton (823086) on Wednesday February 21, 2007 @05:46PM (#18101550)
    This: [] guide is awesome if you want to learn Perl. Concise and articulate, it manages to explain all the major topics of Perl in 66 pages. I recommend working through the entire guide as quick as possible, don't worry about remembering everything as you can always come back to it later. I also recommend having the O'Reilly camel books (Learning Perl, Programming Perl, Perl Cookbook) handy when going through the guide. You can read the books here: [] but you better go out and buy the real thing, worth every penny!!! If your running Windows you'll need to download Perl and a good editor with syntax highlighting: s/5.8/ActivePerl- [] []

    After you install perl open a command prompt and run ppm, this is your simple GUI gateway to CPAN packages (make a mental note). After you get a handle on basic perl checkout Perl/Tk (GUI Toolkit for Perl). The Tk packages are included and installed with ActivePerl... Here's your first Perl/TK program:

    use Tk;
    my $top = new MainWindow;
    $top->configure(-title=>"My First Perl GUI Program");
    my $lab = $top->Label(-textvariable=>\$labelText);
    my $b = $top->Button(-text=>'Click Me!', -command=>sub {$labelText="Congratulations! it worked!" });
    $lab->grid(-row=>0, -column=>0);
    $b->grid(-row=>1, -column=>0);
  • by massysett (910130) on Wednesday February 21, 2007 @05:50PM (#18101608) Homepage
    Stuff like perl -i -pe 's/FOO/BAR/g' *, which will change the string FOO to BAR in all the files in the current directory.

    Sed will do that too:

    sed -i 's/FOO/BAR/g' *

    The review says that the book uses the reader's knowledge of sed, awk, and grep. I figure: why not just use sed, awk, and grep...however, one advantage for Perl here is that (I presume) that line works with any Perl; '-i' is a GNU sed extension and may not work on non-GNU seds...
  • by Tet (2721) <slashdot AT astradyne DOT co DOT uk> on Wednesday February 21, 2007 @05:57PM (#18101736) Homepage Journal
    This strips carriage returns out of a file, and does it pretty quickly.

    No, it's horrendously slow. The traditional Unix way of doing it (tr -d '\015') is around twice as fast on files that are sufficiently large that startup costs are lost in the noise, and even faster on smaller files.

  • by Phroggy (441) * <> on Wednesday February 21, 2007 @06:01PM (#18101782) Homepage
    Have you tried Learning Perl on Win32 Systems []? Windows users wouldn't benefit from the Minimal Perl approach, because they don't have the background it builds on. This book starts at the beginning.
  • Shouldn't that be perl -pe 's/\r$//;'
  • by chromatic (9471) on Wednesday February 21, 2007 @07:06PM (#18102540) Homepage

    You could adopt the practice of doing a lock_keys on the hashref at the end of the object/creation initialization stage, and then if anyone accidentally tries to create a new hash field later, it will throw an error. A simple, effective trick, and I wish it were better publicized...

    Hey, that's Perl Hack [] #87!

  • by roscivs (923777) on Wednesday February 21, 2007 @07:30PM (#18102822) Homepage

    A language which makes a semantic distinction between tabs and spaces may give the appearance of enforcing legibility but in fact does little useful to help legibility.

    A programming language should not make a distinction on meaning based on whether tabs or spaces are used; all whitespace should be regarded equaly (except, understandably, end of line characters).

    Ummm... Python doesn't distinguish between tabs and spaces. I've only written a handful of Python scripts in my life, but I always use spaces to indent, never tabs.

    Furthermore, Python even lets me put in semicolons at the end of my lines. Pretty much the only difference between the way my Python code looks and the way any of my other code looks is that, while the indentation is identical, there aren't any braces in the Python code.
  • by Coryoth (254751) on Wednesday February 21, 2007 @08:29PM (#18103420) Homepage Journal

    Indeed, this is the only thing I mind about indentation in Python: it makes it hard to cut-and-paste code. Fortunately, Emacs has rectangle mode which I find very helpful in indenting a bunch of lines together all at once (C-x t SPACE SPACE SPACE SPACE ENTER to move them all 4 spaces forward, for example).

    Hmm, that seems a round-about way to do things. I presume you never happened to run into some of the nice features in Emacs python-mode, specifically python-shift-left and python-shift-right which will move the selected region left or right one python indent (that is, as many spaces as you have set for your block indentation in python-mode). Usually these are bound to "C-c <" and "C-c >" which lets you easily select a region (such as a pasted block) and move it to the correct indent level very quickly.
  • by VGPowerlord (621254) on Wednesday February 21, 2007 @09:49PM (#18104012) Homepage
    GP quoted the wrong it's.

    And that's nice, but Perl has 10,000+ available modules to do everything from screen-scrape Google news to access Oracle databases (it's greatest strength!!!)
  • by slittle (4150) on Thursday February 22, 2007 @02:53AM (#18105880) Homepage

    You can't put more than 1 statement on the same line as an 'if' or 'else'. "if (increment_them) {a++; b++;}" won't fly.
    You can (but generally shouldn't).

    >>> if True: a = 0; b = 1; c = 2; print a, b, c
    0 1 2

Whoever dies with the most toys wins.