Current area: HOME -> Blogs -> Perl

Blog Posts Tagged With Perl

Today's Topic: Perl's $_ Variable
Posted on Tuesday, January 08, 2008 at 5:30 AM
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:

Read More
Tags: Perl

Perl turns 20, Perl 5.10 released!
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.

Read More

Splitting CSV with regex
Posted on Wednesday, November 21, 2007 at 6:01 AM
I answered a question on the Perl forum today about splitting CSV. CSV is a comma separated format; for example:
blah,blah,blah
You can put values in quotes:
blah,"blah blah",blah
And those quotes make commas within them meaningless too:
blah,"blah,blah,blah",blah
If we do the naive thing and implement it using split on a comma:
my @fields = split(/,/, $string);
Then we will obviously get the Wrong Answer. The question was, is there a regex we can use with split that will do the Right Thing? And the answer was yes, though it took me a few minutes to come up with it. The thing is that we don't want to match anything more than the commas we are splitting on, but we do need to do some analysis on the string that is up ahead (or behind us) to detect if the comma we are seeing is in quotes.

Read More

Perl 5.10 Coming Soon!
Posted on Monday, November 19, 2007 at 10:40 AM
I've spent the last few days at the French Perl Workshop. As well as my brand new talk, I gave two re-runs of two that I had given before. One was entirely new to the French audience, and the other one was from quite a while back and given a face lift so it seemed new (in fact, it was the first talk I ever gave to the Perl community; it was on the topic of web security, and from the web code I encounter it is no less relevant today than it was then). That was 100 minutes worth of talks, which was a pleasure thanks to a great audience.

Read More

Catch Me At Conferences!
Posted on Monday, October 22, 2007 at 7:05 AM
I've got a brand new talk in the works, which I will be delivering at both the French Perl Workshiop (Lyon, 16th-17th November) and the Israeli Perl Workshiop (Tel Aviv, 31st December). I will be talking on the topic of parallelism - why we need to do it, how (not) to screw it up, what Perl 6 will bring to the table and some of the latest research for future ideas, including lock-free data structures. I hope to announce more European dates for the talk over the coming months, subject to it being accepted at more conferences.

Subscribe

RSS Feed RSS Feed

More Tags

.NET C C# C# 3.0 C++ Embedded engineering service eveh3d firmware Hardware Linux Made-In-China offshore Operating System Outsource Perl product development Programming R&D Software

Help

Check out the Blog FAQ.




Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd 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 Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.