security tools Before you start writing code is a series of tasks to be taken into account if we do it right. Of course we can simply open a text editor, write some lines of code and run it, if you need something short, fast and sweet would be fine, but if you're writing a script that we use in the future or pass to another person or group must follow some basic guidelines and highly recommended:
Planning
program flow organize to reuse parts, if necessary
Document, document, document.
Comments A comment is just a text or notes within the code, which is not interpreted, the Perl interpreter simply ignored.
is used to add information about the code or sections of it.
To write comments in Perl
using the # symbol. Any text after # until the end of line is a comment.
# This is a comment
Perl has no multiline comment marker, so to comment multiple lines put a # at the beginning of each. # Sample # comment
Templates, a good habit
A good habit is to make a template as a basis for our scripts, so we get that all we write are similar and consistent meaning to it.
It should include information on who wrote it, when, what does and what version is. Moreover, if we are creating any subroutine in the script, we should also indicate what should happen, what is returned and a description of the function.
An example template would be: [header script]
# / usr / bin / perl-w
#------------------- -
# Script Name:
# Script Version: # Date: # Author: # Description:
# Revision History:
# 1.0 /
: original version #------------
--------
[END header script] [Header function]
#--------------------
# Function # # Version Adde
Input:
# Output: # Description:
#------
-------------- [END header function]
Frontline
The first line of our programs must begin with
#! and path to the Perl interpreter. It is not always necessary but highly recommended, as it indicates the program where to find the interpreter and used to pass options at runtime. For example, to run the script Warning mode (and the interpreter is in / usr / bin) should be our first line:
# / usr / bin / perl-w
This will run our script activating several useful warnings, but there are many different options, for more information it is best to consult the manual for perl.
Related articles:
Perl Manual: Introduction