Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 romping around the Monastery: (4)
As of 2014-12-29 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls