Are you sure you want to logout?

Confirm Cancel

Perl: A Brief Introduction

16 March, 2014 | Post by SQA²

The SQA2 Blog: General

Perl: in this blog, we will discuss one of the most used web languages. We will go into great detail, including the features, code samples and the well-known companies who are using it.

Perl

Perl is a dynamic programming language. It is high-level, general-purpose, and interpreted. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular amongst programmers. Larry Wall continues to oversee development of the core language, and its upcoming version, Perl 6.

The Features of Perl

The overall structure of Perl derives broadly from C. Perl’s nature is procedural; with variables, expressions, assignment statements, brace-delimited blocks, control structures, and subroutines.

Perl also takes features from shell programming. All variables are marked with leading sigils, which unambiguously identify the data type (for example, scalar, array, hash) of the variable in context. Importantly, you can interpolate variables directly into strings through sigils. Perl has many built-in functions that provide tools often used in shell programming (although many of these tools are implemented by programs external to the shell) such as sorting, and calling on operating system facilities.

Perl takes lists from Lisp, hashes (“associative arrays”) from AWK, and regular expressions from sed. These simplify and facilitate many parsing, text-handling, and data-management tasks. Also shared with Lisp are the implicit return of the last value in a block, and the fact that all statements have a value, and thus are also expressions and can be used in larger expressions themselves.

All versions of Perl do automatic data-typing and automatic memory management. The interpreter knows the type and storage requirements of every data object in the program; it allocates and frees storage for them as necessary using reference counting (so it cannot deallocate circular data structures without manual intervention). Legal type conversions — for example, conversions from number to string — are done automatically at run time; illegal type conversions are fatal errors.

Example code

In older versions of Perl, one would write the Hello World program as:

    print "Hello World!\n";

In later versions, which support the say statement, one can also write it as:

    use 5.010;
    say "Hello World!";

Good Perl practices require more complex programs to add the use strict; and use warnings; pragmas, leading into something like:

    use strict;
    use warnings;

    print "Hello World!\n";

Here is a more complex Perl program, that counts down the seconds up to a given threshold:

 #!/usr/bin/perl
 use strict;
 use warnings;
 use IO::Handle;

 my ( $remaining, $total );

 $remaining = $total = shift(@ARGV);

 STDOUT->autoflush(1);

 while ( $remaining ) {
  printf ( "Remaining %s/%s \r", $remaining--, $total );
  sleep 1;
 }

 print "\n";

You can use the perl interpreter for one-off scripts on the command line. The following example as invoked from an sh-compatible shell such as Bash translates the string “Bob” in all files ending with .txt in the current directory to “Robert”:

     $ perl -i.bak -lp -e 's/Bob/Robert/g' *.txt

Well known companies who are using Perl

International Companies: Nokia and Opera Software.

U.S. Companies: Apple, Amazon, Google and Yahoo.

Let's discuss how we can help you! GET IN TOUCH

Please to View This Content.

Not a Member? Register Now

Create New Account