Javatpoint Logo
Javatpoint Logo

Perl First Example

After perl installation, we'll perform our first perl program.

Click on Start-> All Programs->SWIN Perl->Padre, it opens an editor where you can write your script.

Type the following:

Perl statements end with semicolon (;) as shown above. The (\n) is used to denote a new line. As it is a string, it will be enclosed in double quotes (""). And finally 'print' will display it on the screen.

Saving File:

Save the file with (.pl) extension.

Running Script:

To run it, go to Run-> Run Script in the above tool bar. Or in short you can also run it by pressing F5.

Output:

Output will be shown in a different command line window displaying the following letters.


Displaying Output without using Perl Padre

If you are not using Padre editor or any other IDEs, your script will not run from the editor itself.

You'll have to open command line, change to the directory where you stored your script and type print with your file name as shown below.

Here, abc.pl file will run.


Perl print() and say()

The say() is not supported by the older perl versions. It acts like print() with only difference that it automatically adds a new line at the end without mentioning (\n).

Note: you need to mention the version in your script to use the say() function.

Type in:

Output:


Perl Recommendations

We recommend adding two pragmatas 'strict' and 'warnings' in every script. The use keyword is used to load and enable pragma.

These pragmatas will help you to catch some common bugs in your code or may prevent you from making them.

Stating the perl version at top in your script is also recommended. It tells minimum version of perl your code requires.

Next TopicPerl STDIN




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA