0. The programming environment

About the exercises

We will be doing some exercises in Learning Perl, complement or expand up on others in the book and skip many of them, replacing them with exercises of our own. We wholeheartedly recommend you have a go at the exercises at the end of each chapter in LP on your own but will not have time to do most of them in class. Compared to most exercises in LP, we have decided to often start you off with short snippets of working code.

As the course progresses you will notice that the coding style may differ slightly among exercises and teachers. Most Perl programmers develop their own coding style and habits over time so do not be afraid to ask about things you perceive as inconsistent! Perl is a very flexible programming language and generally there’s more than one way to do it, a Perl motto that has its own acronym: TMTOWTDI or TIMTOWTDI (usually pronounced Tim Toady).

Tim Toady

The work-flow of the exercises will typically be such that you will write or edit code in a text editor window and then use a terminal window to run commands and launch your programs. In the first few exercises we will work with simple example data that is contained within the program itself and later we will start reading more complex data from files.

About the computing environment

The course and exercises assumes that you are working in a UNIX or UNIX-like environment such as those provided by Linux or Max OS X, which have easy access to the command-line and a standard set of tools, including Perl. That said, you should always expect a little bit of heterogeneity among UNIX machines. The clusters on UPPMAX, for instance, currently run the operating system Scientific Linux release 6.3 (Carbon) and have Perl version 5.10 installed, whereas the current (as of October 2015) version of Perl is 5.20.3. Some of the recently introduced functionality and syntax presented in Learning Perl 6th edition is therefore not available on UPPMAX and probably not on most current Mac systems either. We will focus on a subset of the language that you are likely to be able to run on any UNIX computer with at least Perl 5.8 (released July 2002) or newer.

The text editor jEdit

In many computing environments where you execute programs on remote machines (such as UPPMAX), you may not be able to use graphical applications to edit files on those machines and will have to edit files directly in the terminal using tools such as
vi, emacs or nano. Throughout this course however you will be running all programs locally on your own computer so we will therefore use a graphical text editor to write code: jEdit.

jEdit is a cross-platform open source Java program that should already be installed on all of the Macs in the computer room. It does syntax highlighting of Perl code, making the source code easier to read. It is a bit bare bones but can be extended with plugins.

Installing plugins in jEdit to extend its functionality

You do not actually need to install any extra plugins to start programming with Perl but we recommend you take a look at the following options if you happen to have time to spare during the exercises.

Launch jEdit and go to: Utilities→Global options and then jEdit→Plugin Manager and press the Update Mirror List button. Select Europe: Swedish University Computer Network (Uppsala, Sweden) and press Apply.

Then go to Plugins→Plugin Manager... and select the Install tab. Search for the following plugins in the filter bar and install them:

  • BufferTabs
  • PerlSideKick (will select additional plugins automatically)
  • CommonControls (needed for EditorScheme)
  • Console
  • EditorScheme
Useful plugins for jEdit
BufferTabs BufferTabs puts tabs above all open files making it easy to switch among files. The plugin should load automatically. No configuration needed.
PerlSidekick Adds a list that can be docked on either side of the text area which make it easier to navigate among features in the source code. 

Go to Plugins→Plugin Options…Plugins→SideKick→Parsers and select Mode: perl Parser: perl

Console A built in terminal that make it possible to run your script from inside the
text editor, without having to switch to an external terminal window. Actually, most programmers tend to use external terminals but it may nice to have the option to use a built-in one. 

Go to Plugins→Plugin Options…→Plugins→Console→Compile & Run and set the compiler/interpreter for edit mode to perl and Compiler→use command: perl and Interpreter→use command: perl. Press Apply.

EditorScheme Makes it possible to easily switch between different color schemes for the syntax highlighting. Programmers that spend much time writing and editing code often prefer a darker scheme which is easier on the eyes than the bright default theme in jEdit. 

Go to Plugins→Editor Scheme→Scheme Selector to change color schemes.

Exercise

Tools

  1. Locate and launch jEdit and the Terminal app and head on to the following exercises!