PERL stands for **P**ractical **E**xtraction and **R**eporting **L**anguage. It is a server-side language, which employs scripting "behind the scenes".
With an HTML file the process is as follows;
- User’s computer asks for the HTML file.
- The Server sends the HTML file.
- The User’s computer interprets the HTML file.
- Sometimes the HTML file tells the User’s computer to ask for more files, like CSS or Icons.
With PERL and other Server-Side langauges the process adds a step (the following is a PERL example);
- The User’s computer asks for the PERL file, usually a .cgi extension
- Sometimes the User also sends additional information with the request
- The Server finds the PERL file and runs the program.
- If there was more information sent from the User or saved on the server, it adds that information.
- If you tell it to, the PERL creates a document that acts like HTML.
- The Server sends that document back to the user
- The User’s computer interprets the HTML file.
- Sometimes the file your PERL script made tells the User to ask for more files, like CSS or Icons.
# Setting Up a PERL File
Most files on a server are simply files that can be read and written to, they do not tell the server to actually perform and execute commands. Your PERL files are different. However the server *assumes* that your PERL files are just read/write files only until you tell it others.
**You need to make any PERL file you create have *Execute* access on the server**. Each FTP client is different, but usually all you need to do is right-click on it, choose Properties, and flip the switches to allow the server to Execute the file.
## File and Folder Structure Matters
HTML files go in the main HTML folder. Styles files go in a styles folder. Images go in an images folder. Other files can go in another designated folder of your choosing.
PERL files *must* be in a **cgi-bin** folder. It should already exist there for you. Always put your *.cgi* files in the **cgi-bin**.
## Tell the server it's not a text file, it's a PERL file.
Just like you had to use `<!DOCTYPE html>` to tell a computer the file was using HTML, you have to tell a server that the file is a PERL script. For nearly every server out there, the command is the same, so type it into your `firstperl.cgi` file;
```perl
#! /usr/bin/perl -w
#tells the Server where the PERL commands are
#the –w switch tells the server that it will write documents.
```
### PERL Modules
Most PERL programmers use chunks of code that were already written by someone else, packaged and installed on the Server. These chunks of code are called ***modules***, and they themselves are written in the PERL language. This means you don’t have to start completely from scratch, all you have to do is tell the file to `use` your favorite modules.
```perl
use cPanelUserConfig; #tells the Server to look for installed PERL modules
use warnings; #a module that will give you warnings when you make a mistake
use diagnostics; #a module that looks for mistakes
use utf8; #a module that lets you use accents in your work
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
#the module that will let you make HTML files, and tells the Server where to put your error messages.
use Fcntl qw(:flock :seek); #tells the server how to manipulate files.
```
# Your PERL is set up.
Now it's time to proceed to an overview of [[NDC Coding/CSE1110 - Structured Programming I/Functions, Parameters, Output and Variables|Functions, Paramaters, Output and Variabes]].
# Video
<iframe width="600" height="400" src="https://www.youtube.com/embed/VtHkcv0uJbk" title="PERL Startup" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>