in reply to Help with sorting/randomizing?
Now, if you have a huge number of ip addresses in a single group, this is inefficient (it will be quadratic in the size of the largest group), but in most cases, this will do.my @groups; while (<DATA>) { chomp; next unless /\S/; if (/^#/) { push @groups, []; next; } push @{$groups[-1]}, $_; } while (@groups) { my $group = shift @groups; my $ip = splice @$group, rand @$group, 1; say $ip; push @groups, $group if @$group; } __DATA__ ... your list goes here ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Help with sorting/randomizing?
by countingcrows (Initiate) on Mar 25, 2012 at 21:41 UTC | |
by JavaFan (Canon) on Mar 26, 2012 at 08:42 UTC |