Every instruction you give a PERL script is a **function**.  You have already used a function in the following line; ```perl use CGI::Carp qw(warningsToBrowser fatalsToBrowser); ``` Another **function** you will use right away is the one that tells the script to print something to the document you want the User to receive. ```perl print "<h2>Haven't you always wanted a monkey?</h2>"; ``` A **parameter** is the conditions you send to the function. - In the first example the **parameter** was the module you wanted - In the second example it was some text for the script to print to the document. **Output** is what results from functions that print information to a document or stream. >CHALLENGE: Using the print function, write out a script that outputs an HTML document that includes a Header and a sentence. # PERL Syntax Every language has appropriate formatting.  HTML had `<tag></tag>`, CSS use the `{ style:setting; }` syntax, and PERL is no different.  Here are some rules for PERL Syntax… - Every function must be concluded with a semicolon to indicate you are done giving information**`;`** - `#` Anything after a hash on any given line is ignored by PERL, and treated as comments. - Certain characters are very important in PERL, such as the following list.  In order to use them you have to escape them by typing a forward-slash \ immediately in front of them; - `" $ % @ ! * & ' \` - Bad example: `print "I have $30.00";` - Good example: `print "I have \$30.00";` - In HTML to start a new line you hit the Enter key.  In PERL you have to tell the system you need a new line with a special 'escaped' code.  That code is `\n` # Scalar Variables While there are many types of variables, we'll only start with one; the **scalar**. A **scalar** variable is like a container.  It holds information.  You can name any scalar you want with a dollar sign in front of it. ```perl $myVariable = "I don't like monkeys"; ``` There are 4 basic types of data in variables; - strings – represented by double-quotation marks. - integers or floats – represented by a numerical value. - booleans – represents a true or false statement. - variable reference - to be discussed in later modules. ```perl $myString = "If I had a million dollars"; $myInteger = 42; $myNegative = -13; $myFloat = 3.14; $myTrue = 1; $myFalse = 0; ``` Every integer, float or boolean can also be treated like a string, but strings cannot be treated like integers, floats or booleans unless they are numerical in nature. # Using Variables Before you can use a variable, you have to tell your script it exists by making an **instance** of it, otherwise called **instantiating** it. ```perl $myVariable = "you can do this"; ``` In a `print` function, you can include that container in double-quotation marks and it will replace the variable with what it contains. Try the following script ... ```perl print "I'll bet \$300 that $myVariable"; ``` If you 'escape' the dollar sign, then PERL won't treat it as though you are calling a variable. However, if you call a print function using single-quotation marks, it will not replace the variable with what it contains; it will type whatever you did (except escapes). ```perl $mycoin = 2; print 'What coin \n is worth \$mycoin?'; print "What coin \n is worth \$mycoin?"; ``` # Hashes - a way of organizing variables A way that browsers oftentimes organize variables is by grouping them in what is known as "key-value pairs", or more simply, **hashes**. A **hash** is a group of scalar variables combined into a common package. Like a **scalar**, it must be instantiated, but this time you do so with a percent sign; ```perl %WINDSOR = (); ``` From here you can place a whole bunch of variables together in what is called a key-value pair.  The **hash** is called using a dollar sign, you set or call a key by placing it inside curly brackets, and then set the value. More details on why this works are discussed in later modules of Object-Oriented Programming. ```perl $WINDSOR{'eyes'} = "hazel"; $WINDSOR{'age'} = 42; $WINDSOR{'alive'} = 1; ``` Note that the keys are *also* scalar variables, not just their partner values. There are then many way you can call the **hash** in your script. ```perl $myFeature = "age"; print "Mr. Windsor has $WINDSOR{'eyes'} eyes and is $WINDSOR{$myFeature} years old."; # The Output #----------- #Mr. Windsor has hazel eyes and is 42 years old. ``` # Constant Variables There are some variables that come constant with a package. For example, because you `use CGI::Carp`, a constant variable that comes from that module is the `%ENV` hash which collects all the data sent to the server by the user. # Outputs More often than not, you will be outputting to the browser of the user. That means you will need to start the document PERL is creating the same way you would have started an HTML file, but with one extra piece of information ... tell the browser you're sending it text. ```perl print "Content-type:text/html\n\n"; print "<!DOCTYPE html>\n\n"; # Add the rest of your print function instructions after this ``` # You're Ready To Accept User Information You can now proceed to the [[Accepting URL Parameters|Accepting URL Parameters]] article. # 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>