in reply to Help with sorting/randomizing?

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 ...
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.

Replies are listed 'Best First'.
Re^2: Help with sorting/randomizing?
by countingcrows (Initiate) on Mar 25, 2012 at 21:41 UTC

    JavaFan thank you. This is working well. However, Class-A is not being randomized.

    184... 64.3.71... 64.3.73... 66...
    What if the file has no group boundaries with hash sign?
      Class-A is not being randomized.
      How can you tell? There's only one element in this group.
      What if the file has no group boundaries with hash sign?
      Then you adapt the program to use whatever your file is using distinguish between groups. Djees man, do you expect me to infer from you single example how the rest of your data may look like?