This is the most accurate answer so far, IMO. I'd like to add some fairly minor points of clarification. The memory being free()d by undef @a is only the memory that the array itself uses to keep track of its elements. The memory allocated for the elements is free()d even when you just do @a= () (unless there are other references to elements elsewhere, in which case undef @a won't free that memory either).
So the only time that it makes sense to undef @a is if @a previously contained a very large number of elements and you don't expect that it will again for a long time.
Also, $#a= -1 is just an obfuscated way of writing @a= (), so please use the latter.
Using defined on aggregates (arrays and hashes) is generally a very bad idea. Please don't do that unless you have very strange requirements and a good understanding of Perl internals.
- tye (but my friends call me "Tye")In reply to (tye)Re: using undef on a array
by tye
in thread using undef on a array
by Anarion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |