Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.

Cheers,

JohnGG


In reply to Re^4: Processing pairs of values from even-sized array by johngg
in thread Processing pairs of values from even-sized array by rovf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (2)
    As of 2020-10-25 21:05 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favourite web site is:












      Results (249 votes). Check out past polls.

      Notices?