background preloader

Perl

Facebook Twitter

Vim for Perl developers - Blog of Leonid Mamchenkov. This is my attempt to provide a clear and simple instructions on adopting Vim text editor for programming needs. I am using Perl as the programming language in the examples, but most of this document will apply equally for any other programming language. Update: This post was translated into Portuguese by Alceu Rodrigues de Freitas Junior. Introduction What is this document? This document is my attempt to provide a clear and simple instructions on adopting Vim text editor for programming needs. Some people may argue that Vim does not need any additional configuration to cover programming needs, while others will say it will never be as good as some Integrated Development Environments (IDEs). Who should read this document? First of all, this document is for people who are already using Vim for their programming tasks.

Prerequisites I assume that the reader has Vim installed on the system and is comfortable with simple text editing in Vim. Structure of the document Methodology Basic Configuration. Padre, the Perl IDE. Gtk2-perl Documentation. For those looking for a quick start, Ross McFarland has written an Introduction to GUI Programming with Gtk2-Perl. We also have some of the example programs from the source distribution. gtk2-perl tries to be perlish, so as to be comfortable and familiar for perl programmers; but it also tries to stick very close to the C API, so that any reference material, tutorials, example code, or programming experience you have with Gtk+ in any language can still be useful. So, the C API reference documentation at developer.gnome.org will be very useful even when developing in gtk2-perl; use it in conjuction with the guidelines for translating the C API to Perl as described in Gtk2::api.

Updated documentation If all else fails, and you feel the need to cry for help, discuss gtk2-perl with the authors on the gtk-perl mailing list. You can search the list archives at markmail or on gnome.org gtk-perl list archives. The Guide to porting from Gtk-Perl to Gtk2-Perl can also come in handy. Tutorials. Regex. Regular expression: a system of pattern masks to describe strings to search for, sort of a more generalised wildcarding. You can use them to scan text to extract data embedded in boilerplate. You can use them to replace boilerplate patterns. Regexes are notoriously difficult to proofread and debug. You must test them in isolation (unit tests) with every pathological data string, and every corner case you can think of. Introduction Java version 1.4 introduces the java.util.regex package. Regex cannot do tasks like look for balanced ( ) or deal with a simple precedence grammar.

Regexes will drive you insane like no other kind of computer programming will. Other Regex Engines Daniel Savarese has written a second Regex package based on Perl regexes. Quoting Reserved characters, aka meta characters are command characters that have special meaning in regexes must be quoted when you mean them literally, as just characters. Again, it won’t hurt to quote punctuation that doesn’t need it. Terminology. Perl Tutorials. Perl Design Patterns Book. PERL Tutorials. Brian's Guide to Solving Any Perl Problem. In general, it's a good idea to declare variables using my instead of using a global or using local. It forces namespace and scope awareness and eliminates pernicious bugs caused by same-named variables with different scope. Practically anything you can do with a local or global variable, you can do with a change in design using my, and you'll get a much more robust design. Also, in general, avoid exporting variables from modules. Exporting methods can sometimes be OK, although I still think it's better to say use Foo::Bar; ... my $barian = Foo::Bar->baz(); so the method's origin is clear.

Variable and method names should be communicative of the intended use; it's better for a name to be long and communicative than short and cryptic. Document, document, document. Also: I'm astonished no one's mentioned using functional spec's and test suites before now. Working with CGI.pm In-Depth - How to create HTTP Headers, Content, Attachments and Redirect with CGI.pm. Finally, we're going to talk about another, similar function called redirect. This one sends a header that informs the client a document has been moved, or is no longer available. If you change the location of a document, or change domain names, it's always a good idea to set up redirects from your old location to your new location if it's at all possible.

This will avoid confusion and broken links, and keep your search ranks from sinking. When redirecting to a document, the only thing you really need to pass the function is the new URI (where you are redirecting to). Let's look at a sample redirect and examine the output: #! In the output, you'll see that the first thing sent to the client is a Status Code, and the default status code is 302 Moved. Status: 302 Moved Location: If you want to send a different status code, like the 301 Moved Permanently, you can pass it with -status option in the function like so:

Working with CGI.pm In-Depth - How to create an HTML document header with CGI.pm. Perl's CGI module, CGI.pm, is a quick and easy way to create CGI applications with embedded HTML. It saves you the hassle of editing and working with actual HTML in your perl programs, or dealing with the overhead of a templating system. We've already had an in depth look at creating the document headers in our first look at CGI.pm - this time we're going to explore how we create the actual start of our HTML document.

This time we're going to take a close look at the start_html, which is used to generate the start of our actual HTML document. Once we've sent our document headers and told the client to expect HTML, we need to send it the proper data. To start with, lets look at the default output of CGI.pm's start_html function: #! Running this program will generate the following output: <? With the default value, it's sending a valid XHTML 1.0 Transitional header, but there's one glaring problem. Complete and very useful perl documentation site.

Perl Module HTML::Template - How to separate HTML from your Perl logic with the HTML::Template Perl module. By keeping your design - HTML, CSS, Javascript - separate from your Perl code, you will save yourself headaches later. Nothing is more frustrating than sorting through a huge application with embedded HTML in print statements. HTML::Template solves this problem by letting you create the HTML in template files and keep them far, far away from your Perl programming. First, like all non-standard Perl modules, you will need to install HTML::Template from CPAN, and then you can include it at the top of your Perl programs with the use statement: use HTML::Template; Before we can get to the Perl part of our program, we'll need to create a template to use in it.

A template is a plain, old HTML file, but when we save it, we'll call it my_page.tmpl: <html><head><title>My Template Page</title></head><body><h1>My Template Page</h1><p>Hello, <TMPL_VAR NAME=USERNAME>, this is a template. Now we're ready to use this template in our Perl scripts by pointing it at the file: Module Links: Creating a simple server monitor in Perl to check the status of your internet services. Ten Perl Myths. Introduction One of the things you might not realize when you're thinking about Perl and hearing about Perl is that there is an awful lot of disinformation out there, and it's really hard for someone who's not very familiar with Perl to separate the wheat from the chaff, and it's very easy to accept some of these things as gospel truth - sometimes without even realising it.

What I'm going to do, then, is to pick out the top ten myths that you'll hear bandied around, and give a response to them. I'm not going to try to persuade you to use Perl - the only way for you to know if it's for you is to get on and try it - but hopefully I can let you see that not all of what you hear is true. First, though, let's make sure we understand what Perl is, and what it's for. Perl is a general-purpose programming language. Perl is sometimes called a `scripting' language, but only by people who don't like it or don't understand it. Perl is hard Wrong. Perl works the way you do.

Let's take another example.