> I'm seeking an equivalent without splice - so that @list remains unaffected. Any suggestions...?
If @list doesn't have millions of entries, I'd just copy to a new @tmp array before prior to using your solution.
But in the sense of TIMTOWTDI and with the power of autovivification ... :)
(demo in debugger)
DB<260> @a= "a" .. "h"
DB<261> @b=(); $i=0; $C=3
DB<262> push @{ $b[ $i++/$C ] } , $_ for @a
DB<263> x @b
0 ARRAY(0x3d7e3b0)
0 'a'
1 'b'
2 'c'
1 ARRAY(0x3d81440)
0 'd'
1 'e'
2 'f'
2 ARRAY(0x3d8e7f8)
0 'g'
1 'h'
DB<264> x @a
0 'a'
1 'b'
2 'c'
3 'd'
4 'e'
5 'f'
6 'g'
7 'h'
DB<265>
HTH :)
NB: you haven't been clear about your row $R requirement.
update
it's a poor man's solution for hippo's part() solution in Re: List into two-dimensional array, but since List::MoreUtils isn't core and List::Util doesn't offer it ...
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|