Written some cool source code? Upload it to Programmer's Heaven.
*/
*/

The Official Programmer's Heaven Blog

Theme Graphic
Theme Graphic

The Official Programmer's Heaven Blog

The blog where the Programmer's Heaven team post stuff.

Subscribe

Author

Often knowledgable, sometimes wise, occasionally funny. The Programmer's Heaven blog team post about a whole range of topics, from practical advice on concurrency control to introductions to lesser known concepts such as functional programming. Don't forget to comment on the posts and let them know what you think, like and hate!

Archive

Tags


Delete Blog
Posted on Tuesday, January 08, 2008 at 5:30 AM

Today's Topic: Perl's $_ Variable

When we are speaking we often use words such as "it" to refer to the thing we are currently talking about. For example, "My computer has just had a PSU failure. It is on fire." You could say that "it" refers to the current topic, which we assigned in the previous sentence.

Anyone who's read many of my ramblings will know that one thing that interests me is the use of features of natural language in programming languages. What if we could express the idea of the current topic in a programming language, though?

Turns out that is exactly what the $_ variable in Perl is for. It is sometimes also known as the "default variable". If you have read many Perl scripts you will probably have come across things like this:
chomp;
s/\[b\](.*?)\[\/b\]/<b>$1<\/b>/;
print;
The question that people often ask on seeing this is - chomp what? Bind a substitution to what? Print what? A fairly substantial number of Perl built-ins, when invoked a parameter missing, will use the default variable $_ instead. You could re-write the above as:...
Comments: 9 Tags: Perl

Posted on Tuesday, December 18, 2007 at 3:17 PM

Perl turns 20, Perl 5.10 released!

Today represents exactly twenty years since the very first release of the Perl programming language! On 18th December 1987, Larry Wall released Perl 1.0. Twenty years on there has been another release of Perl: Perl 5.10. Five years in development, Perl 5.10 makes some significant advances on the Perl 5.8 series both in terms of performance and features, while maintaining backwards compatibility with Perl 5.8.

The regex engine, always a strength of Perl, has seen a whole raft of improvements. Some of these include performance enhancements, and others are new features; if is now, for example, much easier to write recursive regexes for matching nested structures. You can also name captures rather than just referring to them by number, which will bring readability enhancements...
Comments: 9 Tags: Perl, Perl 6, Perl 5.10


corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.
Resource Listings