Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

"Good" style for splicing arrays

by LanX (Saint)
on Nov 14, 2008 at 12:34 UTC ( [id://723633]=perlquestion: print w/replies, xml ) Need Help??

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 (κς,πμ,πλ)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://723633]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-03-29 14:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found