Apart from all those otherwise good advices there is the most important thing. You should not use delete() on arrays. It doesn't do what you most likely expect. delete() is fine on hashes, but on arrays you should use splice(). Try to run this:

use Data::Dumper; my @a = (1,2,3); print Dumper(\@a); delete $a[1]; print Dumper(\@a);
As you can see the 1st item in the array was not removed, but only set to undef, the number of items in the array has not changed. I do think what you want is
@a = (1,2,3); splice @a, 1, 1; # replace 1 element(s) starting on position 1 by noth +ing print Dumper(\@a);


In reply to Re: deleteing array elements I get mad!! by Jenda
in thread deleteing array elements I get mad!! by kurreburre

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.