first perl program

here is a simple "Hello, World!" program in Perl:

refer to:‮itfigi‬dea.com
#!/usr/bin/perl

use strict;
use warnings;

print "Hello, World!\n";

Here's a breakdown of what's going on in the code:

  • The first line (#!/usr/bin/perl) is called a shebang and tells the operating system to execute this file using the Perl interpreter.
  • The next two lines (use strict; and use warnings;) are called pragmas and enforce stricter rules for variable usage and catch common programming mistakes.
  • Finally, the print statement outputs the string "Hello, World!" to the console followed by a newline character (\n) to start a new line.

Save the above code in a file with a .pl extension, such as hello.pl. Make the file executable using the chmod command:

chmod +x hello.pl

Then, you can run the script by typing the following command in the terminal:

./hello.pl

This should output the message "Hello, World!" to the console.