in reply to Process order

You can sort the keys by value,

my @sorted = sort {$po{$a} <=> $po{$b}} keys %po;
You would do better associating a name to coderef through a hash, an arrangement usually called a dispatch table. What you're trying is calling through symbolic references.

(Added) With your calling pattern of calling on and modifying $input, you might consider writing your subs to modify their argument.

my %process = ( PR1 => sub { $_[0] = process1($_[0]) }, PR2 => sub { $_[0] = process2($_[0]) }, # . . . ); my %po = ( PR1 => 4, PR2 => 2, PR3 => 1, PR4 => 3, PR5 => 5, ); for (sort {$po{$a} <=> $po{$b}} keys %po) { $process{$_}($input); }
It would be best if you made sure all the keys of %po existed in $process. How are you deciding priority? That could have a huge influence on how you actually do this.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Process order
by anniyan (Monk) on Jun 09, 2006 at 11:27 UTC

    Zaxo thanks for your prompt reply.

    I don't want to change the subroutine names (process1, process2..). The keys in the above hash (process names) are got from another input file. They are CODE which i cant change.

    Regards,
    Anniyan
    (CREATED in HELL by DEVIL to s|EVILS|GOODS|g in WORLD)

      Look again. PR1 calls process1, PR2 calls process2, etc. Nothing was renamed.

      Update: Oops, it seems the code wasn't originally there.