Perl Wiki

Scripting is the art of writing short programs usually in an interpreted language like perl. Perl scripts many times are simple text files with the file extension .pl and a logical filename that tells in one word or phrase what it does.

To quote Larry: "A program is something you give the audience; A script is something you give to the actors."

See Wikipedia:Scripting language for more insight.

Hai Santosh[]

The traditional opener:

#!/usr/bin/perl
# hello.pl - Hello World!
use strict;
use warnings;
print "\nHello World!\n";

line 1

#!/usr/bin/perl

The #! is a hint for some operating systems of what program should be called to process the text file containing the Perl program, which has to be executable. On GNU/Linux this can be achieved by setting the x (executable) bit with chmod.

/usr/bin/perl is the basic location for the perl interpreter on, for example GNU/Linux, (this can vary). This magic first line is called the shebang. It's possible to specify additional switches after the name of the program. A classic one is -w. Note however that this switch has now more or less been replaced with warnings pragma (compiler directive): use warnings; (see below).

line 2

# hello.pl - Hello World!

A # begins a comment which stays in effect for the remainder of the line. It's nice to comment your code to let others know what's going on.

line 4 and line 5

use strict;
use warnings;

The first pragma turns on additional checking. The second pragma turns on warnings. A lot of experienced Perl programmers refuse to even look at the rest of your Perl program if those two lines are missing and most of the time for a very good reason.

line 7

print "\nHello World!\n";

The print statement connects, by default to <STDOUT>, the standard output which is generally your terminal. The string that gets printed must be enclosed in quotes, either single (') or double ("). The \ns tell your terminal to begin a newline. Each statement must end with a ; (semicolon).

The above example is a fairly typical way to write a Perl program (also called Perl script). If you have perl installed and can run that script without errors, you're on your way!

perl.wikia.com[]

Here at Perl Wiki, we apply scripting to the world of wikia and wikicities and are attempting to share what we learn as we go. Much of learning perl involves just diving in and doing it. It helps to have some applications in mind and some useful goals. WikiaPerl might someday become a full-blown CPAN module especially for Wikia use, but it has to start somewhere. For now, the Perl Wiki:Library is here to collect some more scripts and ideas. Feel free to experiment, brainstorm, and share your experiences.

Wikipedia[]

Wikipedia:User:Pearle is a useful script written, maintained and operated by Wikipedia:User:Beland to help sort and catalog large chunks of content on Wikipedia. Have a look.

See also[]