When to Use Perl

When designing an interactive Web site, you have a wide choice of languages to develop in. Not even CGIs have to be written in Perl. Some languages, such as PHP and ASP, are embedded into HTML pages, and other languages, such as C, are compiled and can offer high performance. So when should you use Perl?

There are some circumstances in which it is convenient to be able to write standalone scripts with no need for a Web server; for instance:

  • You may want to invoke programs directly from the command line; you can do this easily with Perl.

  • You may want to invoke programs from the cron scheduler. If, for example, you have a database that needs a regular update, perhaps a once-nightly process to be run, you can write the application in Perl and invoke it from cron.

  • Your program may take a long time to run. Perl processes, when invoked directly, do not have the timeout limitations of programs invoked via Apache.

There are also performance benefits in some circumstances:

  • Perl has powerful text processing routines (regular expressions); this makes it particularly useful for handling user input from a form on a Web site, verifying and analyzing it.

  • Because Perl is an interpreted language, it is generally quicker to develop Perl programs than programs in a compiled language such as C because you do not have the overhead of recompiling the program every time you want to retest it.

However, there are a few downsides. Perl is not the easiest language to learn quickly, and for the inexperienced coder, it can be daunting to view the code left by another developer. There are those enlightened ones who are addicted to Perl, but more simple folk will probably find languages such as PHP easier to learn, without losing much functionality (indeed PHP has much in common with Perl).

Perl is not embedded into HTML pages (although versions of Perl do operate like this). This means that to compile an HTML output, complete with all the HTML tags required for page layout, navigation, and images (usually static content) can be a tedious exercise. HTML can either be directly output from Perl, or held in a template file that Perl can parse, inserting dynamic content as it goes. Although there are tools to help with Web interfacing matters (such as CGI.pm), the implications of this are that it's less elegant to generate a Web page from Perl than PHP, and you may prefer to do things an easier way. The upshot is, development times for Web applications are often shorter in PHP than for Perl.

Furthermore, if an application must run fast and demands that every last ounce of performance is squeezed out of the system, a compiled language might be a better option. When a Perl script is invoked, the Perl interpreter must first be loaded into memory, which is an additional performance overhead. These things may be issues with programs that are run frequently on a busy Web site. If this is the case, a compiled language such as C may be the fastest option.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.53.93