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 running 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 simplest program you can write. It simply prints out the sentence: 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

Prerequisites

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/

Video 1 - How to download Perl (Video tutorial)

Perl

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

Video 2 - How to install Perl (Video tutorial)

Create your first Perl program

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

Video 3 - How to create your first Perl program (Video tutorial)

Open Notepad

To start coding in Perl, you must 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.

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 bring 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")

Video 4 - How to write your 'hello world' program in Perl (Video tutorial)

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.

Video 5 - How to run the hello world program (Video tutorial)

Run the program

After writing the code we can run our program. Start by opening the command 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 Perl Hello world 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 it didn't understand the instructions. To correct the mistakem, 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.

Video 6 - How to handle a syntax error in Perl (Video tutorial)

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 about the nature of the error and where it happened. These messages are helpful in finding and fixing mistakes in the code.

error
Figure 6 - Error

Summary

This tutorial helps you get started with Perl by explaining the necessary steps from the basics, like what you need to install and how to write your first Perl program. This knowledge gives the ability to apply the Ozeki PHP SMS solutions to your Perl application for better performance on SMS organizing. Using Perl SMS API is beneficial because it allows you to personalize your messaging system based on your work team's needs, which results in a smoother workflow.

You can find more information about Perl solutions and the Ozeki SMS Gateway, so make sure that you study more. I recommend reading the next guide about how to send SMS from Perl.

Now is the best time to download the Ozeki SMS Gateway, so do it!

More information