JDT

 

FREE Downloads
Articles
Tutorials

 

Create and Run a Simple Perl Script


In this tutoral we will look at how to create and run a very simple Perl script.

Writing the script

Open a text editor, for example, NotePad, and enter the following lines of code:

#!/usr/bin/perl
print "Goodbye cruel world\n";

The line beginning with #! is the shebang (in Unix) line, and needs to be the first line in the script. It defines the path name where the Perl Interpreter is installed. If you are using Windows, you can omit this line if you want - the script will still run fine.

The second line simply prints (on the screen) the message 'Goodbye cruel world'.

Save the file as goodbye.pl. You could probably get away without adding the .pl extension to the filename, but I always add it to identify such files as Perl scripts. Make a note of the directory/folder where you have saved the file.

Running the script

You need to run the script from a command line prompt, so open a terminal window/MS-DOS prompt. Change to the directory/folder where the goodbye.pl file is located, and type the following command:

perl goodbye.pl

Hopefully, you will see the message 'Goodbye cruel world' displayed on the screen. If you don't, then there is a problem - either with the script itself, or with the execution of the script.

Error messages

If the script did not work, you probably received one of the following error messages:

  • 'Bad command or filename' or 'command not found'. This means that Perl has not been added to the PATH variable. See your operating system help/documentation for information on how to fix this problem.
  • 'Can't open perl script goodbye.pl: A file or directory does not exist'. This probably means that you are not in the folder/directory where you saved the script, in which case you should change to the correct location.
  • If you get a syntax error, it probably means you have mis-typed the contents of the file. Open the file and fix any mistakes.

Author: Backrubber
John Dixon Technology Ltd







Go back to Perl Tutorials home page

Go back to Tutorials home page



Earnings Tracker is John Dixon Technology's FREE open source accounting / bookkeeping software tool.

Earnings Tracker is aimed at contractors and freelancers, and enables you to perform many bookkeeping and accounting tasks, helping you to keep track of your company's earnings and outgoings.

The software is written in PHP and MySQL and is available to use for FREE online, or as a FREE download.

As it is written in open open source, you are free to modify the code yourself, enabling you to produce a customized version of Earnings Tracker that fits your own specification.

Earnings Tracker can also be used simply as a dividend, corporation tax, or VAT calculator.

Need free accounting software
 



JDT

Copyright Notice for John Dixon Technology Ltd

Privacy Statement

Terms & Conditions