LanX has asked for the wisdom of the Perl Monks concerning the following question:

unfortunately it seems that this thread printing 20 characters in a line. already got out of the standard "10 newest threads view" and so out of the awareness of the monks ...

I offered 2 answers now, but I'm not sure which one is the "preferable" style...(in the sense of maintainability, stability, sideeffects, readability,...)
thats what splice() is for...
splice without splice()

what do you think is better?

---
Which song? ;)

Replies are listed 'Best First'.
Re: "Good" style for splicing arrays
by ccn (Vicar) on Nov 14, 2008 at 12:48 UTC

    The first is better.

    In second case you may have some undef values in the last chunk. It is not good. If you chose nonspace delimeter for elements you'll see that.

      Good point, so the second technique must be combined with a definde grep if undefined values matter...

      Thx! 8 )

      ---
      Which song? ;)
        But if you have relevant undefs in your array, things go south. That is why splice is better than the other thing... and it's shorter and so, even more perl-y.
        []s, HTH, Massa (κς,πμ,πλ)