Thank you for pointing that out, I rarely come across List::MoreUtils as it is not a core module so I wasn't aware of part. Very useful if you can work with the resulting AoA but it seems a bit awkward if you really do need separate arrays.
knoppix@Microknoppix:~$ perl -MList::MoreUtils=part -E '
> @parts = part {
> ++ $i;
> $i % 5
> ? $i % 2
> ? 0
> : 1
> : 2
> } 1 .. 20;
> @odds = @{ $parts[ 0 ] };
> @evens = @{ $parts[ 1 ] };
> @fivers = @{ $parts[ 2 ] };
> say qq{@odds};
> say qq{@evens};
> say qq{@fivers};'
1 3 7 9 11 13 17 19
2 4 6 8 12 14 16 18
5 10 15 20
knoppix@Microknoppix:~$
knoppix@Microknoppix:~$ perl -E '
> push @{
> $_ % 5
> ? $_ % 2
> ? \ @odds
> : \ @evens
> : \ @fivers
> }, $_ for 1 .. 20;
> say qq{@odds};
> say qq{@evens};
> say qq{@fivers};'
1 3 7 9 11 13 17 19
2 4 6 8 12 14 16 18
5 10 15 20
knoppix@Microknoppix:~$
Perhaps I'm missing something. I have tried pushing references to @odds etc. onto @parts before using part without success so I can't seem get away from having to do @odds = @{ $parts[ 0 ] }; etc.
-
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.
|