Thanks for replies.

The purpouse of this mini-script is to list the rows from a database loaded
in memory ($ref_db is the reference to hashtable that cotains the DB). So I
want to order the fields by different sort rules, and make the proccess as
abstract as it's possible with a subrutine (sub cmpRule). This sub must
recieve the rules (by array argument, for example), and create the body that
will be called by sort.

This is what I've done since I wrote the message (now, it only works with
one rule, but I think it's easy to do multiple-rules sort from here)

The comparation subroutine:

sub cmpRule
{
   return '$$ref_db{$a}{$$ref_fields{$opt}[0]}'.
           ' cmp $$ref_db{$b}{$$ref_fields{$opt}[0]}';
}

...#some code

my $func = &cmpRule;

foreach my $row (sort {eval($func)}    keys %{$ref_db}){
...#some code
}


It works but, do you think it's a good solution?

Thanks for your time.

Sergio.

Reply via email to