test sort function
Last active
December 3, 2015 13:13
-
-
Save gonter/f8534a9384f4547e87ff to your computer and use it in GitHub Desktop.
sort test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use Data::Dumper; | |
$Data::Dumper::Indent= 1; | |
my @PIDS_shuffled= <DATA>; chop(@PIDS_shuffled); | |
# fisher_yates_shuffle (\@PIDS_shuffled); | |
# print "PIDS_shuffled:\n", join ("\n", @PIDS_shuffled), "\n";exit; | |
my @objects1= map { { 'PID' => $_ } } @PIDS_shuffled; | |
sub sort_pid_array_hashes | |
{ | |
($$a{PID} =~ /o\:(\d+)/)[0] <=> ($$b{PID}=~ /o\:(\d+)/)[0]; | |
} | |
sub fisher_yates_shuffle | |
{ | |
my $array = shift; | |
for (my $i = @$array; --$i; ) | |
{ | |
my $j = int rand ($i+1); | |
next if $i == $j; | |
@$array[$i,$j] = @$array[$j,$i]; | |
} | |
} | |
# print "objects1 : ", Dumper (\@objects1); | |
my @objects2= sort sort_pid_array_hashes @objects1; | |
# print "objects2 : ", Dumper (\@objects2); | |
print "PIDS_sorted:\n", join ("\n", map { $_->{PID} } @objects2), "\n"; | |
__DATA__ | |
o:78084 | |
o:17532 | |
o:21847 | |
o:43965 | |
o:6972 | |
o:94261 | |
o:6974 | |
o:57125 | |
o:561 | |
o:12962 | |
o:190 | |
o:42312 | |
o:48160 | |
o:64966 | |
o:6380 | |
o:67628 | |
o:402 | |
o:67953 | |
o:46544 | |
o:19588 | |
o:61714 | |
o:95821 | |
o:18246 | |
o:91298 | |
o:78565 | |
o:37756 | |
o:12668 | |
o:81225 | |
o:76704 | |
o:52049 | |
o:191 | |
o:30148 | |
o:32741 | |
o:42411 | |
o:63021 | |
o:68771 | |
o:95378 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment