No such thing as a small change | |
PerlMonks |
Re: Perl array deleteby CountZero (Bishop) |
on Apr 06, 2011 at 06:11 UTC ( [id://897667]=note: print w/replies, xml ) | Need Help?? |
If you think it through, deleteing an array element is a somewhat strange concept, except for the highest numbered element. Think of an array as an apartment building. You may empty a single floor (set the value of the array-element to zero or the empty string) or even erase all traces of its former occupants (set the value of the aray element to undef), but you cannot take the floor itself away. That would really confuse all tenants living above it! When they arrive home in the evening, they would find their apartment having dropped one level. If you have a fifth floor in your building, you must have all the lower numbered floors (zero to four) as well. In other words, as long as there are still array elements with an higher index, you cannot delete the lower numbered ones without fundamentally changing the structure of the array itself. PS: Of course functions like pop, push, shift, unshift do change the structure of the array, but only from the top or bottom end. CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
In Section
Seekers of Perl Wisdom
|
|