I think the following will give you a very good spread. I concocted it from the top of my head, so I don't garantee results.

use strict; use warnings; open(my $fh, '<', '...') or die("Unable to open input file: $!\n"); # Group domains into an AoA. # Very efficient since the input fileis already sorted by domain. my @grouped; my $prev_domain = 'invalid domain'; while (<$fh>) { chomp; my $addr = $_; my $domain = ...; if ($domain ne $prev_domain) { $prev_domain = $domain; unshift(@grouped, []); } push(@{$grouped[0]}, $addr); } # Sort groups by group size. # Gives something like: # @sorted = ( # [ qw( g1 ) ], # [ qw( f1 ) ], # [ qw( e1 ) ], # [ qw( d1 d2 ) ], # [ qw( c1 c2 c3 ) ], # [ qw( b1 b2 b3 ) ], # [ qw( a1 a2 a3 a4 a5 ) ], # ); my @sorted = sort { @$a <=> @$b } @grouped; my @ordered; my $prev_last = 0; my $break = 0; my $offset = 0; for (;;) { my $p = shift(@sorted); last if not defined $p; my $last = $#$p; if ($last != $prev_last) { $prev_last = $last; $break = @ordered / $last; $offset = 0; } foreach my $i (reverse 0..$last) { splice(@ordered, $i*$break+$offset, 0, $p->[$i]); } $offset++; } { local $, = ", "; local $\ = "\n"; print(@ordered); }

In reply to Re: Need to create a blender to mix up lines from a file by ikegami
in thread Need to create a blender to mix up lines from a file by Bugorr

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, details, 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, summary, 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.