turnstep already pointed you at undef, but I'm left wondering, "Why do you want to destroy the list?" Ok, I know the most obvious answer, "To reclaim the memory," but that leaves me thinking that you are doing something else wrong. Think about it, if you have a list, and you don't need it anymore, shouldn't Perl take care of it for you? Well, yes, but only if you tell Perl to do so. And the way to do this is to scope your array, so that when you are done with it, it goes out of scope. Now if you are not already doing this, then you are also not using strict. It is never too late to start using this great tool.

But Adam, you say, I am scoping the array using my, I just wanted to reuse the array inside the same scope. Well, don't. But if you are just writing a hack, and good programming isn't part of it, then in that case, use undef, or set the array to an empty array, or set the index of the last element to -1.

$#arrayName = -1;

In reply to Re: Elegant way of destroying a list by Adam
in thread Elegant way of destroying a list by JojoLinkyBob

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.