Perl 5.10: Some Praiseworthy New Features

Filed under: Computers, News
Posted by: Ashutosh
31
Jan
2008

“Perl”, a dynamic scripting language, introduced a new and improved version, the first in over five years.  This is the first update since 2002 to the “practical extraction and report language”. “Perl 5.10″ adds both new language features and an improved Perl interpreter, according to community site Perl Buzz.

“Perl” is a dynamic scripting language widely used in everything from Linux system utilities to Web servers to full-blown graphical enterprise applications.

“Perl” has a long 20-year history now and during all these years it gained massive popularity by assimilating the syntax from many predecessors, making it really easy to use for anyone already versed in ‘sed’, ‘awk’, ‘grep’, ‘csh’, ‘C/C++’, ‘Lisp’, and so on.

Perl’s syntactical flexibility sometimes makes perl scripts challenging to read. On the other hand, the languages like ‘python’ with its rigid syntax structure have arguably gained ground in recent times over ‘Perl’, for applications that are developed collaboratively.

In addition to that, scripting languages specially-made for use on the Web, like’ PHP’ and ‘Ruby’, have eroded some of perl’s once formidable share of the dynamic Web server scripting scene.

One of the most attractive feature of the ‘Perl 5.10′ is the new ‘or’ operator, //, which is a “defined or” construct.

For example, the following statements are syntactically equivalent:

$foo // $bar

defined $foo ? $foo : $bar

An expert would definitely identify that the first line is much more compact and more readable. This clearly means that it is “$foo defined”. Therefore, an equal sign also can be placed like;

$bar //= $foo;

It is almost the same as writing;

$bar = $foo unless defined $bar;

Another praiseworthy new feature of this programming language is its “smart match operator”. ‘Perl Foundation’ described this as “a new kind of comparison, the specifics of which are contextual based on the inputs to the operator”.

This remarkable “smart match operator” appears to be aiming at making Perl’s relatively strong typing easier to work with. The “~~” operator apparently guesses the type from context, allowing lazy comparisons.

Of this new feature, ‘ Perl Buzz’ comments, “The result is that all comparisons now just do The Right Thing, a hallmark of Perl programming”.

For instance, to find if scalar $needle is in array @haystack, it would now require to apply the ” ~~ operator”;

if ( $needle ~~ @haystack ) …

‘Perl 5.10′ has a specific support for the named “regex statements”. Programmers will now be in a position to avoid the hard to decipher dreaded lines of $1 $2 etc. It will be easier to understand what’s going on in complex ‘regex scripts’ such as the ‘Markdown’.

Perl guru Ricardo Signes highlighted  its new language features  that include  a ‘switch statement’ said to go “far beyond” those found in C, C++ or Java and Regex improvements which is a “Named captures” aimed at reducing the need for positional captures along with Recursive patterns said to be useful in parsing.

All new features can be upgraded without breaking the existing scripts simply because these features have been turned off by default. It has been enabled for progressive upgrading the scripts with the “use” syntax.

Scott Gilbertson explains this in a better way. He advises to add the line use feature ’switch’; prior to a block of code where you’d like to take advantage of the new switch statement in Perl 5.10 and then turn it off after upgrading that block of code using the statement no feature ’switch’;. New features can be enabled by name or as a collective group using the statement use feature ‘: 5.10′.

Apart from this ‘switch statement’ there is also a new ‘say statement’ “which acts like print() but adds a newline character and a state feature, which enables a new class of variables with very explicit scope control” says Scott Gilbertson.

‘Perl’ is an interpreted language instead of being just a compiled language. This unique characteristics of ‘Perl’, makes it a human-readable code that can easily be interpreted a ‘Perl Interpreter’.

“With the 5.10 release, the interpreter gains speed, while shedding weight”, ‘Perl Buzz’ claims. Other interpreter improvements include ‘Relocatable installation’ for more file system flexibility, more portable Source code, and fixing of many small bugs.

‘Perl 5.10′ has several other interesting improvements including a faster interpreter with a smaller memory footprint, and better error messages. Many experts in programming have found that “Perl 5.10’s new features are definitely worth the upgrade and a must have for anyone who uses Perl on a daily basis”.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Site of the month

Epagini Title: Epagini
Romanian SEO Company

Latest WP Theme

Magaling Name: Magaling
Author: Padd IT Solutions

Latest on Wp Market

Rewards of Freedom Name: Rewards of Freedom
Author: MGC design team