Slashdot Mirror


Minimal Perl for Unix and Linux People

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 slashdot.org 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 bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

16 of 332 comments (clear)

  1. Minimal Perl for Unix and Linux People by mobby_6kl · · Score: 2, Funny

    Minimal Perl for Unix and Linux People? Is this the result of a perlgolf competition between perl-related books?

  2. *sigh* by A+beautiful+mind · · Score: 4, Funny

    Perl (Practical Extraction and Report Language)
    That's a backronym. By those standards you could also call PHP Pretty Hellish Performance.
    --
    It takes a man to suffer ignorance and smile
    Be yourself no matter what they say
    1. Re:*sigh* by grcumb · · Score: 4, Funny

      Perl (Practical Extraction and Report Language)
      That's a backronym. By those standards you could also call PHP Pretty Hellish Performance.

      ITYM 'Poorly Hung Perl'. 8^)

      --
      Crumb's Corollary: Never bring a knife to a bun fight.
  3. Cryptic? Complex!? by setirw · · Score: 5, Funny

    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.


    So wrong! Just look at the following example:

    #!/usr/bin/perl -w

    length q caller vec and print chr oct ord q qx eq and print chr ord q ref or and print chr ord q or no and print chr ord q else and print chr ord qq q q and print chr ord q tie gt and print chr ord qw q sin q and print chr ord q q eq and print chr ord qw q sin q and print chr ord q sin s and print chr ord q cmp lc and print chr ord q split s and print chr ord qw q lc q and print chr ord q ne sin and print chr hex length q q bless localtime ref q


    Run that. Nothing cryptic or complex at all.

    (BTW, it prints "Perl is simple!")
    --
    This message printed on 100% post-consumer recycled electrons.
  4. Re:PERL backronym by morgan_greywolf · · Score: 5, Funny

    Nope.

    Stands for Python'll Eventually Replace this Language.

    or, optionally:

    Perl Eats Ruby for Lunch :-D

  5. Re:So you like the book by realmolo · · Score: 4, Funny

    8/10 is a *good* review. You've been reading too many IGN game reviews.

    IGN scoring works like this:

    5/10 - The game runs

    6/10 - The game is an FPS

    7/10 - The game has team-based mulitplayer online play

    8/10 - The game runs at 190 frames-per-second

    9/10 - The game is made by a publisher that buys advertising on IGN

    10/10 - The game is made by a publisher that buys A LOT of advertising on IGN
     

  6. Basic way to clean up your Perl code by TheRealMindChild · · Score: 1, Funny

    10 CurrentFile = Dir("*.pl") 20 Do while len(CurrentFile) > 0 30 Kill CurrentFile 40 CurrentFile = Dir() 50 Loop 60 End

    --

    "When life gives you lemons, don't make lemonade. Make life take the lemons back!" -- Cave Johnson
  7. Re:Python by licious · · Score: 1, Funny

    crap, I was wondering why Tom Cruise, John Travolta and R Kelly were with me in this smallish room filled with coat hangers and ties.

    --
    I hear there's rumors on the Internets that we're going to have a draft.
  8. Perl Scripting for the Dummy Like Me (fixed) by andy314159pi · · Score: 2, Funny

    #!/usr/bin/perl -w
    ##Oh boy I'm using an advanced scripting language!
    system("/usr/local/bin/csh csh.script_1");
    system("/bin/rm /home/me/file_to_be_removed");
    system("/usr/local/bin/application & application_output ");
    system("/usr/local/bin/csh csh.script_2");
    #
    system("/bin/cat "I know Perl" > resume.txt");
    exit

  9. Re:I {} Perl by timster · · Score: 4, Funny

    "Speak" Perl, right. Because what Unix really needed was a combination of the specificity of natural language and the friendly syntax of awk.

    --
    I have seen the future, and it is inconvenient.
  10. Re:Perl Script for the Dummy Like Me by Phillup · · Score: 2, Funny

    You don't eat or drink or mow the lawn;
    You just type on Slashdot all day long. And then one day... you learn how to format and preview.
    --

    --Phillip

    Can you say BIRTH TAX
  11. Re:Cryptic? Complex!? by Ikoma+Andy · · Score: 3, Funny

    But one of the main problems with Perl is it's so easy to right totally unmaintainable... Dude, I'm thinking it's not Perl that was your problem...
  12. I've got a question about subtypes of acronym by spun · · Score: 3, Funny

    Remeber that a "Backronym" (hate that word!) is a subtype of acronym.

    Would Muhammad Ali's GOAT (Greatest Of All Time) line of food products be considered a snackronym or a blackronym?

    --
    - None can love freedom heartily, but good men; the rest love not freedom, but license. -- John Milton
  13. Re:Cryptic? by stefanlasiewski · · Score: 3, Funny

    Cryptic perl is a myth. It's only cryptic if you don't understand it.

    Cryptic 32-character hexadecimal MD5 hashes are a myth. It's only cryptic if you don't understand it.

    --
    "Can of worms? The can is open... the worms are everywhere."
  14. What I love most about Perl is it's SPEED! by clayne · · Score: 2, Funny

    (yes I pre-ran them both multiple times to reduce cache affects)

    [src] $ time perl -e '$tdata = "../../tests/ctok.in.2"; $sz = -s $tdata; print "sz == $sz\n"; open(FH, $tdata); while (<FH>) { @t=split(/[ :#]+/, $_); $c += $#t; } print "c == $#t\n";'
    sz == 96252007
    c == 12301001

    real 0m31.877s
    user 0m31.662s
    sys 0m0.148s

    [src] $ file ctok
    ctok: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, not stripped
    [src] $ time ./ctok ../../tests/ctok.in.2 " :#"
    sz == 96252007
    c == 12301001

    real 0m2.417s
    user 0m2.280s
    sys 0m0.132s

    And yet I still proudly use C. Let the prophets K&R reign supreme.

  15. Re:Should I read this or continue with sed/awk? by doom · · Score: 3, Funny

    The most annoying people in the world have all switched to Python
    Heh, I guess I'm one of the most annoying people in the world then. Are you sure it's not just that the grapes are probably sour anyway?

    Well, I didn't mean that to be taken personally... but consider the fact that ESR is on your side.