in reply to Sort by what?

my %sort = ( by_title => \&by_title, by_whatever => \&by_whatever, ); my $var = 'by_title'; for (sort { &{$sort{$var}} } @array) { ... }

Replies are listed 'Best First'.
Re^2: Sort by what?
by Roy Johnson (Monsignor) on Jul 16, 2004 at 18:07 UTC
    This simpler version
    $var = 'by_title'; # or $var = \&by_title; sort $var @array;
    will work, where $var can be given either the name of the subroutine or a reference to it. If validation of the sub name is necessary, it ought to be done separately from the call to sort.

    We're not really tightening our belts, it just feels that way because we're getting fatter.