This is a bit of an explanation on what the other monks were doing with @array.

splice(@array, 0, 8);

splice destructively removes elements from @array, so you have to ask if you really want to do that. Since you are not splicing elements into the array (like you would splice a rope), splice probably doesn't make sense in this context.

A slice (like you do with pizza or pie, not like a rope) (see below) seems to be what you want, and it is a little more intuitive to read. The splice just accesses the elements, without removing them.

@array[0..8];

The other monks comments on how to do a foreach still apply to. So you can just foreach over a slice. It's better than repeating statements or using a for loop with a counter variable. If you want just part of the array, you can specify the start and stop boundaries of slice using something like @array[1..6]

foreach $item (@array[1..6]) { $item =~ s/\.//g; }

So this modifies only certain elements of the array, and it's pretty darn clean to look at. You may to modify the indexes (indices) if 1..6 isn't what you want exactly, but you get the general idea.


In reply to Re: How to make it simple? by flyingmoose
in thread How to make it simple? by Anonymous Monk

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.