www.fachtnaroe.ie



Web This site

Perl - Editing Your Source Code.

The first program

If you haven't already done so, create a folder called perl_progs, enter that folder and create the Hello World program. Use the name hello.pl for the file to clearly identify the pupose of the program as well as the type of file. Into that file, enter the following source code to make your own Hello World program. Using one of the two methods indicated below enter the code exactly as given, complete with indentation, capitalisation, symbols etc as shown:

#!/usr/bin/perl
# This is my first program.

  print "Hello World!\n";

When the program file is complete and saved, it will need to be made executable. To do this, change the mode of the file by toggling its execute bits on by typing chmod +x hello.pl and you should be able to run the program from the command line using the name of the file prepended with "./" like this: ./hello.pl

How to create and edit the file is discussed next...

CLI Editing: vi

You can use the slightly ancient editor known as vi. It has the advantage of being available on most *NIX platforms so once you get used to it your knowledge will be transferable to other systems. That being said, you might prefer to have that part of your brain amputated afterwards; vi is old, awkward and strict and may cause you slight mental damage if you let it.

To edit a program with vi first cd to the directory with the file; then type vi filename on the command line. Immediately enter insert mode by pressing i. Enter or edit your program as required.

When finished, press the ESC key once, press :wq and return to write and quit.

If you just want to save, press ESC : w and then i to return to insert mode.

If you just want to abandon a file, press ESC : q! and then return to exit.

If you want to over-write a read-only file (assuming you have authority to do so), press ESC : w! and then i or q as required to continue editing or to quit.

GUI Editing: kwrite

Below is a VNC session showing a 'traditional' X Windows task-bar-free session using twm (the name of the Window Manager). Though apparently primitive, you can carry out all the necessary tasks for your program - plus many other tasks in this envionment. The relative simplicity of the display also means that there is less of a transmission (bandwidth) over head due to the absence of complicated graphics.


In the example above the program kwrite is used. It's a simple reliable text editor. To edit the source code of your program files type kwrite hello.pl and the editor will start with the program loaded.

Another option is to type a space and an ampersand after the line given above, like this: kwrite hello.pl &

This allows control of the terminal session to be returned to you so that you can have the editor running while simultaneously able to test your program in the terminal. This is the situation in the screengrab shown above.

Last updated: 20120108-18:18
back to top
Fachtna Roe, Senior College, Central Technical Institute, Clonmel, Ireland.