Friday, March 15, 2013

Perl: The Language Everybody Wants to Declare Dead

by +Dietrich Schmitz

I keep looking, but I still haven't found a language that compares with Perl.  The level to which one can go with it soars above other languages with ease.  Perl will take you through a project and provide the deliverables.

It seems that many react and cringe when they hear the word Perl.  It's a funny reaction to me.  Because, all of the documentation for Perl is superb.  Writers like +Randal L. Schwartz or +Gabor Szabo will guide you with great thoughtful tutorials in their respective books and on-line websites.

My reaction to comments to the negative is that most are ill-informed and if a prospective student were to spend just two hours reading +Randal L. Schwartz's Learning Perl, they will have built a solid foundation upon which to expand their technical skill set.

Perl is found resident on most Unix, BSD, and Linux systems by default.  It often plays a large part in many 'behind the scenes' activities running on your system.  If you invest the time to learn, I would say it would not be a wasted effort as once done, Perl will be their in your toolbox for you to grasp and use on so many occasions throughout life.

Will Perl eventually die?  Some say it will.  But if you go by a recent study from RedMonks that measures the spectrum of programming languages in use on GitHub, it is evident that Perl is quite alive and well.


The RedMonk Programming Language Rankings: January 2013



Put forth the initial effort to learn Perl.  While the initial hill climb is steep, once mastered, Perl is powerful in the hands of the learned.  Perl can and does do the 'heavy lifting' in so many ways as exemplified by the CPAN repository.  CPAN is one step away  for anyone with Perl with a diverse set of open source modules ready to fill gaps in your programming needs.

Perl isn't just for writing projects; it is also good for quick 'one-off' utilitarian functions and can be quite convenient when invoked right from the Bash command line.  This one-liner upper-cases an entire text file:

$ cat sample.txt
Practical Extraction Report Language

$ perl -pi  -e “tr/[a-z]/[A-Z]/” sample.txt

$ cat sample.txt
PRACTICAL EXTRACTION REPORT LANGUAGE


Often, I visit +Gabor Szabo's excellent Perl5 Maven website to see what he is up to and come away learning something I didn't know before.  At his site you'll find his most excellent new book Perl Maven for Beginners, including in eBook downloadable format.  You can also find regular posts of his ideas and a dedicated section to tutorials especially made to coddle and encourage the newcomer to venture into this feature-rich, powerful programming language.  Here's a tutorial on reading a comma separated value (CSV) file and the requisite code:

#!/usr/bin/perl
use strict;
use warnings;
 
use Text::CSV;
 
my $file = $ARGV[0] or die "Need to get CSV file on the command line\n";
 
my $csv = Text::CSV->new ({
  binary    => 1,
  auto_diag => 1,
  sep_char  => ','    # not really needed as this is the default
});
 
my $sum = 0;
open(my $data, '<:encoding data-blogger-escaped-die="" data-blogger-escaped-fields="$csv-" data-blogger-escaped-file="" data-blogger-escaped-my="" data-blogger-escaped-n="" data-blogger-escaped-not="" data-blogger-escaped-open="" data-blogger-escaped-or="" data-blogger-escaped-ould="" data-blogger-escaped-utf8="" data-blogger-escaped-while="">getline( $data )) {
  $sum += $fields->[2];
}
if (not $csv->eof) {
  $csv->error_diag();
}
close $data;
print "$sum\n";

I can assure you from experience that for every 1 line of Perl, writing an equivalent piece of code in C will yield a ratio of 10 or more lines to accomplish same.  This is not to suggest that Perl serves to replace the venerable C language--certainly not.  But there are many applications where Perl excels and is the right tool for the job, particularly systems integration and the Internet web development.

So, please.  Make the investment.  Randal and Gabor will be there to help you.  I promise.   Learn Perl and it will be with you to serve your needs always.

-- Dietrich
Enhanced by Zemanta

18 comments:

  1. Hello,

    you have some strange stuff in the code for CSV reading - lines 7, 16, 24.

    ReplyDelete
  2. Yes, I see that. I know that the code needs escapement in certain languages (HTML, CSS), but I am not sure if any is needed for Perl. This is what is embedded in the page:



    #!/usr/bin/perl

    use strict;

    use warnings;



    use Text::CSV;



    my $file = $ARGV[0] or die "Need to get CSV file on the command line\n";



    my $csv = Text::CSV->new ({

    binary => 1,

    auto_diag => 1,

    sep_char => ',' # not really needed as this is the default

    });



    my $sum = 0;

    open(my $data, '<:encoding data-blogger-escaped-die="" data-blogger-escaped-fields="$csv-" data-blogger-escaped-file="" data-blogger-escaped-my="" data-blogger-escaped-n="" data-blogger-escaped-not="" data-blogger-escaped-open="" data-blogger-escaped-or="" data-blogger-escaped-ould="" data-blogger-escaped-utf8="" data-blogger-escaped-while="">getline( $data )) {

    $sum += $fields->[2];

    }

    if (not $csv->eof) {

    $csv->error_diag();

    }

    close $data;

    print "$sum\n";






    ---------
    The Javascript makes a pass over the code to add escapement if needed.
    So, I might check to see if their is an update that resolves this bug.


    Thanks
    --Dietrich

    ReplyDelete
  3. Be wary of using GitHub's data for judging Perl's popularity. GitHub treats anything that looks like a programming language and it cannot parse as Perl, including, until recently, the GPL copying notice. Currently, it is still known to count some Python and Bash programs as Perl.

    ReplyDelete
  4. Can you supply documentation that supports this assertion?

    ReplyDelete
  5. Hipster language users want to kill perl.
    but They don't realize the destination of their favorite languge environment is perl. :)
    They are just enjoying making the new wheel without known there are already robust and high-quality wheel(cough..cough Perl).
    Stop making the new wheel and Just USE PERL! haha

    ReplyDelete
  6. Do you know that Perl 5 is 3 years younger than Python and just 1 years older than Ruby ?
    Perl 5 is not yet old enough to die.

    The day good to die for perl will be also good season for Python and Ruby dead.
    Stop FUD on Perl, hipsters ... :)

    ReplyDelete
  7. This is a great article. Very well articulated.

    ReplyDelete
  8. What has this article to do with Perl? Your examples can be dealt with by other languages in much the same manner and the same or less amount of code.

    Therefore the article totally misses its point. You haven't told us WHY everyone wants to declare Perl dead. You haven't told us WHY Perl is better suited for the (trivial) tasks you presented as examples.

    ReplyDelete
  9. Not dead. More active than ever. Smaller slice in a bigger pie, but more people absolutely working with Perl than ever. More new releases. More CPAN submissions. Cooler code. And Perl6 in the form of Rakudo is actually mostly usable now.

    ReplyDelete
  10. Thanks for stopping by Randal!! :)

    ReplyDelete
  11. Adalberto Corona Jr.March 24, 2013 at 4:58 AM

    Just now I ordered the book "Learning Perl" , to get started . Since I now installed FreeBSD OS on new purchased hardware, learning perl will accommodate me just fine. Wish me luck. Thanks.
    Live Long and Prosper !

    ReplyDelete
  12. Learning Ruby is more rewarding IMO. It has a cleaner syntax, can also do those famous powerful one liners, has OO built right into the language, has a great regexp engine (Oniguruma) and is only mildly slower than Perl.

    ReplyDelete
    Replies
    1. Ruby? Come again after making a valid lexical variable & scope. it's not beauty. Rubist just want to assert that they are beauty themselves. have you seolusly learnt Perl? :) STOP propaganda like. kindergarten boys with shallow knowledge.

      Delete
  13. Thank you for your $1.25 contribution to my profitability!

    ReplyDelete
  14. As ugly as Perl can be sometimes, it works, and it works damn well. It, Groovy, and Bash are simply fun to write in.


    Nice article, even though there's not much in it about people actually wishing for Perl to die (not as much as Java, at least).

    ReplyDelete
  15. Reminds me of learning to respect Rexx.

    ReplyDelete
  16. I don't see why wanting to kill Perl, it has its own niche. But calling this for debate is asking for language wars, which nowadays consist mostly by Perl, Python, Ruby and Scala people.


    I think Common Lisp is much more versatile (as a language, not counting libraries) than any of these, but the other languages (yes, including Perl) are much more alive, so what could I do?

    ReplyDelete
  17. I've been using perl since 1993. I describe it as the "Swiss Army Knife" of programming languages. My one complaint with perl is that, after learning it, I have trouble convincing myself I need to learn another programming language and unfortunately the world is always enamored with the latest, greatest shiny new thing.


    Cheers,
    Dave

    ReplyDelete