Howto: Write script in Perl

www.‮‬lautturi.com
Howto: Write script in Perl

To write a script in Perl, you will need to follow these steps:

  1. Create a new file using a text editor. Open a text editor, such as vi or nano, and create a new file. This file will contain the Perl script.

  2. Add the #! shebang line at the top of the file. The shebang line specifies the interpreter that should be used to execute the script. For a Perl script, you should use #!/usr/bin/perl.

  3. Write the Perl code for the script. In the script, you can include any Perl code that you would normally enter at the command prompt.

  4. Save the file and make it executable. Save the file with a .pl extension, and make it executable using the chmod command:

chmod +x script.pl
  1. Run the script. To run the script, enter the name of the script file at the command prompt:
./script.pl

Here is an example of a simple Perl script that displays the message "Hello, World!" and the current date:

#!/usr/bin/perl

print "Hello, World!\n";
print "Today is " . localtime() . "\n";
Created Time:2017-10-29 22:08:48  Author:lautturi