Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://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":



  • 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.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (None)
    As of 2024-04-25 03:56 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found