Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Adding an new element after every 5th element in array

by boftx (Deacon)
on Nov 26, 2013 at 20:32 UTC ( #1064469=note: print w/replies, xml ) Need Help??


in reply to Re: Adding an new element after every 5th element in array
in thread Adding an new element after every 5th element in array

Nevermind, this is completely wrong. :(

I think hdb's example could be simplified a bit plus avoid any old-size remainder problems like this:

while( @array ) { push @newarray, splice @array,0,$nset; next if @newarray % ($nset * $every); # no need for a counter w +ith % op push @newarray, $newelement; # add the new element }
It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1064469]
help
Chatterbox?
NodeReaper snacks on some Soylent Green

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2016-12-08 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (141 votes). Check out past polls.