in reply to Help with sorting/randomizing?

Use a nested hash with the top level key the class A addresses, class B as the second tier, class C as the third tier and an array of class D addresses as the ultimate value.

If that doesn't make sense write a little code, show us where you are having trouble, and we'll help further. PerlMonks is not a code writing service, but we will write almost any amount of code if we think you are making an effort and learning from it.

You may find perllol helpful if you haven't used nested data structures in Perl before. To a reasonable extent you can replace [...] with {...} when using nested hashes instead of nested arrays. Note too the "See Also" section at the end.

True laziness is hard work

Replies are listed 'Best First'.
Re^2: Help with sorting/randomizing?
by countingcrows (Initiate) on Mar 25, 2012 at 19:58 UTC
    Thank you Grandfather. I don't really know where to start or how to start really. This is beyond me. If someone could show me a bit of code, I think I can pick up from there. I know what perlmonks is, I have often turned here for help in the past. But this issue I am not able to solve, and I thought someone experienced here could give me a hand (for a donation, or whatever). Thanks. J

      In your OP you say "All my attempts have been futile." which implies you have attempted a solution. Show us your last attempt and describe the problem you had with it.

      Did I say PerlMonks isn't a code writing service?

      Welcome along to PerlMonks by the. Were you here before as an Anonymous Monk, or have you gotten yourself a new name?

      True laziness is hard work
        while($line = <$in_fh>) { chomp $line; if ($line =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)/) { $a = $1; $b = $2; $c = $3; $d = $4; $ip = "$a.$b.$c.$d"; $classc = "$a.$b.$c"; } next unless defined $ip; push @{ $ips{$classc} }, $ip; } foreach $classc (sort keys %ips) { print $ips{$classc}[rand @{$ips{$classc}}] . "\n"; }
        Code I pasted does not show.