Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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.


Comment on Re^2: Adding an new element after every 5th element in array
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1064469]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2015-07-29 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls