On July 21st Greg Gorman led a discussion on Perl (Practical Extraction and Report Language). If you’re planning to write an application with Perl and don’t know where to start, this is the transcript for you. If you couldn’t join us then, enjoy the transcript and we hope to see you on our next live Guild Meeting. You can find a schedule of Guild Meetings in your weekly TechProGuild Notes TechMail, or on the Guild Meeting calendar.
On July 21st Greg Gorman led a discussion on Perl (Practical Extraction and Report Language). If you’re planning to write an application with Perl and don’t know where to start, this is the transcript for you.If you couldn’t join us then, enjoy the transcript and we hope to see you on our next live Guild Meeting. You can find a schedule of Guild Meetings in your weekly TechProGuild Notes TechMail, or on the Guild Meeting calendar.
Note: TechProGuild edits Guild Meeting transcripts for clarity.
Welcome to the Guild Meeting
MODERATOR: Welcome to today’s Guild Meeting. Today we are proud to bring you TechRepublic’s own Greg Gorman. Greg will be speaking about Perl in just a moment, so get all your best questions ready!
Now, ladies and gents, I give you Greg Gorman!
GREG GORMAN: Hello all. It’s a great time to be a developer, with open source tools like Perl readily available. If you’re looking for a place to start learning Perl, you have to start with www.perl.org. If you are a book learner, there are no better sources than O’Reilly’s two Perl classics: Learning Perl and Programming Perl. The Learning Perl and Programming Perl books are the Perl bibles in my mind. Learning Perl is an excellent tutorial book with exercises and topics covered in each chapter. Programming Perl is better as a reference manual.
Another tremendous resource, and one of Perl’s strengths, is www.cpan.org, the Comprehensive Perl Archive Network. There, you can find thousands of modules already written and available for use.
There is also a tremendous online presence of Perl resources, similar to the Linux support that is readily found.
SEEWER: Do you have any favorite Web sites that you recommend for Perl?
GREG GORMAN: As far as sites, I’ve recommended www.perl.org, www.perl.com, www.activestate.com, and www.cpan.org, among others. Additionally, you can subscribe to mailing lists, which will answer many of the getting started-type questions.
JLWALLEN: What are the best newsgroups and mailing lists for Perl?
GREG GORMAN: I’d say WRT mailing lists. Since I was initially using Perl from my Windows PC at home, I got the Perl version from ActiveState. If you go to their site and click on support, you can get to the mailing lists. I still receive the daily digest of Perl-Win32-Users and Perl-Web-Users, as I believe they are called. You can also search the archives of those mailing lists.
JLWALLEN: I know in the Linux world Perl is an amazingly useful tool, for everything from networking to shell scripting. Within the Windows world, is it the same situation?
GREG GORMAN: Perl for Windows was a tad behind the UNIX implementation, but it works very well. I don’t have any metrics regarding performance, but one of the great things about Perl is its portability between Windows and UNIX. Here at TechRepublic, we use Perl for its unsurpassed ability to parse text, in particular with content processing.
JLWALLEN: When you write an application (or script) in Perl, for a particular platform, does that platform have to have the Perl binary or is the newly created application self-contained?
GREG GORMAN: Standard Perl requires the Perl binary; however, you can use a freeware utility Perl2exe to convert the Perl script into an exe.
JHANSKNECHT: Do you have specific examples of types of uses at TechRepublic?
GREG GORMAN: I can think of several uses; one of the principal uses is in the processing of content. The Perl scripts we use in content processing move source files from one destination to another. Another function of the scripts is to parse the meta information and update a database that is used by the live site for dynamic matching of content with user attributes. At one point, we wrote a small script (less than 60 lines) as a heartbeat for the live site, making an http request to a page, checking for a response, and then sending an e-mail page if it did not get the expected response. This allowed us to proactively and easily monitor the site.
JLWALLEN: Does Perl use regular expressions?
GREG GORMAN: I’m glad you asked about regular expressions. Perl has the best regular expression processing of any language I’ve ever seen.
GREG GORMAN: The history of Perl (which is explained in the Perl books I mentioned) is that it grew from awk and sed plus C scripting in UNIX. It combines the power of all of them! That was plus C language plus UNIX scripting!
MODERATOR: Are you talking about UNIX shell scripting?
GREG GORMAN: Absolutely! Yet another of Perl’s strengths is that if you know C and a little UNIX shell scripting, you can jump in right away and program Perl.
An example of Perl code
JLWALLEN: Does Perl use the $ character in the same way that Linux does? In other words, if I create a variable called VARIABLE and set it equal to something that is not going to change, can I use $VARIABLE throughout the script?
GREG GORMAN: WRT $’s in Perl; I think the answer is yes. You access variables with $’s. Let me check for a quick snippet of code as an example. Here’s a sample line of Perl that converts the input filename from .txt to .htm:
$outfile =~ s/\.txt/\.htm/ig
That takes the current string and does a simple substitution.
JLWALLEN: What is the ~ character in the line? It looks like the equivalent of the procmailrc * character, which indicates the beginning of an expression.
GREG GORMAN: The ~ character is actually an operator for Perl. I apologize for not knowing the name of it, but I will say it works very well.
JLWALLEN: My mistake. The * character in the procmail syntax means “the preceding item will be matched zero or more times.” The new line character in procmail is ^.
GREG GORMAN: The new line in Perl is \n.
JLWALLEN: That is similar to C and C++.
GREG GORMAN: Very, very similar to C. In fact, you can (nearly) program in C, and it will run in Perl.
JLWALLEN: Wow! I wish my C knowledge were stronger.
MJACKMAN: Are there disadvantages to using Perl?
GREG GORMAN: Perl, out of the box, is an interpreted language. Therefore, for high-performance requirements, it may not be the best choice. Perl has taken some serious strides to address performance; among the first was mod-Perl, which is an Apache module that greatly increases the speed of CGI scripts by caching the compiled Perl and reusing the object module.
MJACKMAN: Could you explain what you mean by “out of the box”? Does this mean you can make Perl not be an interpreted language?
GREG GORMAN: By out of the box, I mean prior to converting the Perl script to an exe or by using mod-Perl to cache the executable.
Compiled vs. interpreted code
JLWALLEN: Another basic question for you. Does Perl require compilation? Compared to say C or C++, how resource intensive is the compiled (or not) code? What I’m getting at is, say I want to use an older machine as a print server or a dedicated document processing system, will Perl be able to do this efficiently on this older machine?
GREG GORMAN: Perl does not require compilation, as I said, it’s interpreted. It is not particularly resource intensive, and I expect that it would run pretty well on an older box.
Perl vs. CGI
MJACKMAN: What is the relationship between Perl and CGI?
GREG GORMAN: CGI scripts and Perl scripts are often confused. Perl is one type of CGI script, probably by far the most common type. But a CGI script can be a UNIX shell script or something else, as well.
MJACKMAN: I guess the confusion is because Perl is run through cgi-bin.
GREG GORMAN: Yep, that’s the source of the confusion. That and the fact that the file extension is usually .cgi.
GMJACKMAN: Greg, is this mod-Perl included in Apache now? What about in Linux? And if I’m running an older version of Apache, can I just get an update from them?
GREG GORMAN: Regarding apache and mod-Perl, I’m a little short of experience there. The mod-Perl module is freely available, and I presume www.apache.org or www.perl.org can point you in the right direction for more specifics. Sorry about that, but I don’t have a lot of personal experience with those.
MJACKMAN: I have heard that Perl can make a site less secure. What are your thoughts on this?
GREG GORMAN: I don’t believe that Perl will make a well-secured site any less secure. You obviously don’t want to leave the cgi-bin directory available for users to upload (and then execute) scripts of course. But I’m not currently aware of any gaping holes in it.
Perl vs. Python
JLWALLEN: How would you compare Perl to Python? Can Perl serve up GUIs like Python?
GREG GORMAN: I am not very familiar with Python, but I’d say that Python might have the edge on Perl WRT GUIs. There are probably several Perl modules that will get you close, though.
EENGELKING: Is Perl only a Web-based programming language?
GREG GORMAN: Web-based only? Heck no! Perl’s strengths are in regular expression handling (read, parsing strings easily). As I alluded to earlier, we use Perl here for processing our raw content, moving it from one place to another, extracting meta information, etc. It’s a great tool for that.
Using Perl in a large-scale application platform
SEEWER: Many people use Perl as a language to build tools with. What are your thoughts on using Perl as a development language for large applications, rather than using C or C++?
GREG GORMAN: Many people are scared of Perl as a large-scale application platform, because it can appear to be hard to read.
JLWALLEN: What licensing issues does Perl face?
GREG GORMAN: Perl is GNU licensed. You can pretty much do whatever you want with it, within the confines of the GNU license, and you can make money doing it. You do not have to pay for a license to run it.
Perl for Windows vs. Perl for UNIX
SEEWER: How different are the versions of Perl for Windows vs. UNIX? Do you need to worry about loss of functionality between the two versions?
GREG GORMAN: I’ve not experienced a loss of functionality between Windows and UNIX. The only difference is you can issue system commands on UNIX that don’t port to Windows (some to DOS but not to Windows).
MODERATOR: Well gentle people, we’re out of time. Thank you all for showing up and remember to come back next Tuesday at 9 P.M. to have a rousing discussion on dumb user stories!
Our Guild Meetings feature top-flight professionals leading discussions on interesting and valuable IT issues. You can find a schedule of Guild Meetings in your weekly TechProGuild Notes TechMail, or on the Guild Meeting calendar.