in reply to Re: Sorting Hash: Sort Criteria Moved Into Eval
in thread Sorting Hash: Sort Criteria Moved Into Eval

Thanks aristotle for your exemple. It got me to understand much better eval with sort. Here is how I solved my problem. I wanted to sort on column 0, then 1, then 2... variably depending on user input. Here is my test code maybe it will help others.
push my @tableau,[222,234523676,26256,5645,634,56,3456,5345623]; push @tableau,[333,2346,2356457,347,7745,67,3462]; push @tableau,[3.3,2341,2356457,347,7745,67,3462]; push @tableau,[333,2349,2356457,347,7745,67,3462]; push @tableau,[777,67567,4568458,45845,48458,4578]; push @tableau,[999,67567,4568458,45845,48458,4578]; push @tableau,[444,67567,4568458,45845,48458,4578]; push @tableau,[111,67567,4568458,45845,48458,4578]; my $grandeur; foreach (@tableau){ my $compteur = 0 unless $compteur; $grandeur = $#{$tableau[$compteur]} if ($grandeur < $#{$tableau[$c +ompteur]}); $compteur++; } my @sorter; foreach (0..$grandeur){ my $sortCriteria = "\$tableau[\$b][$_] <=> \$tableau[\$a][$_]"; push @sorter,$sortCriteria; } $sorter = join " or ",@sorter; print "$sorter\n"; my $sortfunc = eval "sub { $sorter }"; @sortedKeys = sort $sortfunc 0..$#tableau; print "@{$tableau[$_]}\n" foreach @sortedKeys;
Good luck.