Ozeki 10 SMS Gateway

Perl tutorial: Hello world

This tutorial helps you get started with Perl. It explains what you need to write your first Perl program. It starts with the basics: you will learn where you can find and download the tools needed, how to install these tools and it will take you all the way to building and runing your code. If you have never written a Perl program before this is the place to start. We have created this article, so you can get started with Perl, and move on to our sms examples. If you are already familiar with Perl, you can jump directly to one of the following SMS projects.

Perl sms examples:

Perl send sms with the HTTP rest api (code sample)
Perl send multiple sms with the HTTP rest api (code sample)
Perl schedule sms with the HTTP rest api (code sample)
Perl receive sms with the HTTP rest api (code sample)
Perl delete sms with the HTTP rest api (code sample)
Download the latest Perl sms api library from Github

What is Perl

Perl is a programming language. It is similar to a natural language, like English. It is used to talk to a computer. The major difference between a natural language and a programming language is that, programming languages have a more rigorous structure, to help the computer understand it better.

What is a Perl Hello world program

The Perl hello world program is the most simple program you can write. It simply prints out the sententce: Hello world on the computer screen. The Hello World program is the first program developers write in any programming language.

How to write your first program in Perl

To write your first program in Perl:

  1. Check prerequisites
  2. Setup Perl
  3. Open Notepad
  4. Save Notepad with .pl file extension
  5. Write Hello World program in Perl
  6. Use print("Hello world") for printing
  7. Run your Perl Hello World program
  8. Check the output


Here is what you need to get started. To write your first computer program in Perl, you need a Windows computer and example code presented below.

  • Windows 10 computer
  • Perl
  • Ozeki Hello World example project

Download Perl

You may download Perl from the following URL: https://strawberryperl.com/


To write your first Perl program, you need to install Perl. The following video shows you how this installation can be done.

Create your first Perl program

After Perl has been installed, you need to open the Notepad.

Open Notepad

To start coding in Perl, you mus first open Notepad. Type "notepad" into your search bar on the bottom left. The results will return the application (Figure 1). Click on it to open Notepad.

Figure 1 - Open Notepad

Save as

Once you entered Notepad you should create a file. Do this by clicking on "File", then click on "Save as" (Figure 2). This will birng up a new window allowing you to name and save the file.

save as
Figure 2 - Save as

Name the file

After clicking on Save as, you will be asked to choose a path and specify a name. Type the name next to "File Name: ". Click on the Save button to create the file (Figure 3).

file name
Figure 3 - File name

Write your 'hello world' program in Perl

The first program you write in any programming language is the 'Hello world' program. The sole aim of this program is to print the term 'Hello world' to the computer screen. In this example the program consists of two lines of code: The first line: puts "" prints the text.

print("Hello world")

Write the code

Now you can write the hello world code in the newly created file. First enter the print command (Figure 4). Inside the parentheses and quotation marks you can write the message you want to display. In this case, "Hello World!".

write code
Figure 4 - Write the code

Run the Perl 'hello world' program

To run the hello world program, you need to press Enter.

Run the program

After writing the code we can run our program. Start by opening the comman prompt (Figure 5). First you must change directory to where your file is located. This is done with the cd command. Next, type perl.pl to run your code. You can see that the message has appeared in the command prompt window.

run the program
Figure 5 - Run the program

What happens if I make a mistake in Perl

If you make a mistake, when you write your instructions in Perl, you will get a Syntax error. The computer will highlight the line with error in red, and it will tell you why didn't it understand the instructions. To correct the mistake you need to go back to the text editor and modify the program. Programs say they "fix the error" when they correct mistakes.

What is syntax error in Perl?

Syntax error means I don't understand. If you talk to somebody in English and he does not understand what you say, he will reply with "I don't understand". If you talk to a computer in Perl and the computer does not understand what you say, he will reply with "Syntax error".

In the code below we will create a mistake intentionally by not putting a semicolon after the Hello World line. You will see, how the computer reacts, how we fix the error, and how we run the computer program successfully.

How to handle a syntax error in Perl?

In the code below we will create a syntax error intentionally by not putting a semicolon after the Hello World line. You will see, how the computer reacts, how we fix the error, and how we run the computer program successfully.

Errors in perl

If an error occurs due to an invalid syntax in the code, an error message gets displayed (Figure 6). Upon running the program, you get notified that it encountered and error. This error message contains information abput the nature of the error and where it happened. These messages are helpful in finding and fixing mistakes in the code.

Figure 6 - Error


Now that you have completed the five simple steps above, you have made your first step in becoming a VB.Net software developer. This program may seam simple, and it may not do much, but this is how great things start. The next step in your learning jurney will be creating an HTTP request.

More information