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.

In reply to Re^2: Sorting Hash: Sort Criteria Moved Into Eval by aanhouden
in thread Sorting Hash: Sort Criteria Moved Into Eval by mdog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.