Welcome to the Monastery | |
PerlMonks |
Re^3: Help with arraysby roboticus (Chancellor) |
on Sep 22, 2012 at 12:58 UTC ( [id://995101]=note: print w/replies, xml ) | Need Help?? |
The phrase "unknown length" simply means that you (the programmer) don't know how long the array is beforehand. The intent is to make you think of a way to accomplish the task that particular bit of information. Perl, however, will always know how many items are in the array. If you build that kind of knowledge into your code, you make your code less easy to reuse. For example:
As you can see, the difference between the subroutines is that in the first one, the programmer assumes that all arrays it will be used with have exactly 5 elements. In the second example, the programmer instead asks the array how long it is. Notes:
...roboticus When your only tool is a hammer, all problems look like your thumb.
In Section
Seekers of Perl Wisdom
|
|