|
|
| |
<_Torna alle categorie
Perl: The Complete Reference Autore / Release: Martin Brown Editore / Produttore: Mc Graw Hill
ISBN: 0072120002 Prezzo Listino: € 49,99 Prezzo Shop: € 25,00 Risparmio: € 25,00 (50%)
Note: 1150 pagine
Valutazione (da 1 a 5):    

Descrizione
Everything we have covered so far covers the basics of programming Perl. We’ve looked at how to communicate with the users, how to manipulate basics data types and how to use the simple control statements that Perl provides to control and manage the flow of execution in a program.
One of the fundamentals of any programming language is that there are often repeated elements in your programs. We could cut and paste from one section to another, but this is messy. What happens when you need to update that sequence you just wrote? You would need to examine each duplicated entry, and then make the modifications. In a small program this might not make much of a difference, but in a larger program with hundreds of lines it could easily double or triple the amount of time you require.
Duplication also runs the risk of introducing additional, typographical errors. If you forget to make a modification to one section, or make the wrong modification it could take hours to find and resolve the error. A better solution is to place the repeated piece of code into a new function, and then each time it needs to be executed you can make a new call to the function. If the code needs modifying, then you modify it once and all instances of the function call use the same piece of code.
This method of taking repeated pieces of code and placing it into a function is called abstraction. In general, a certain level of abstraction is always useful – it speeds up the programming process, reduces the risk of introducing errors, and makes a complex program easier to manage. For the space conscious, the process also reduces the number of lines in your code.
|
|
|
|