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:...
Posted on Tuesday, December 18, 2007 at 3:17 PM
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...