Making Script Readable
Keep your script clean and learn how to 'escape' characters in this section.
Keep your script clean
We also included more information that will make your script more recognizable and easer to track:
# author: #modified by: # date: #Purpose:The Purpose comment is the most important because after several month or years you will not want to read the entire script to know what it does. The other information is also necessary in order to track who did what to that script. In a small environment or for personal scripts they can (but should not) be skipped, in medium and large environments, they are a necessity.
We also advise you to do two things in order to make your code clear and easy to follow. First, type the 2 quote symbols first and then put the cursor inside the symbols and start typing. This way you will not forget to put the last one by accident. The second one is to use the print function ability to have several arguments on the same line to separate the actual statement to the new line character n. It doesn’t change the way the script is executed but make the code clearer.
Escaping characteres
When interpreted, the sign will escape the next character. It is used to create a new line n or tabs t. The n or t is not echoed because of the . Because of this it is impossible for an interpreted comment (one between “” ) to echo the character on its own. In order to print the character you will need to tell Perl to escape the in order to print it.
Example:
You want to echo a windows path. If you print “c:windows “Perl will echo c:windows. In order to print the sign you need to escape it.
print “c:\windows” is the way to write it to have the right output.
Quotes will also presser spacing. If you put 20 space in your argument Perl will echo 20 spaces.
A problem will arise when you want to echo single or double quotes inside double quotes, or single quotes inside single quotes. If you try it Perl will return an error. In order to bypass that problem Perl allows you to create your own delimiter.
print q{} (for single quotes)
print qq{} (for double quotes)
You can use any non-alpha-numeric character as your delimiter {} [] && ^^ %% etc…
That first script isn’t that complicated, but it is poised as the foundation of good coding. Good coding habits now will save you a lot of time and energy in the future.