in reply to Sorting question

Let's assume sub GeneralizedFunction is passed $flag (with possible 'A', 'B', 'C', 'D', 'E') which specifies which sort routine to use. Let's also assume you have sort functions Sort1, Sort2, Sort3, Sort4 and Sort5.

You could then write:

use strict; use warnings; my %Functions = ( 'A' => { func => \&Sort1 }, 'B' => { func => \&Sort2 }, 'C' => { func => \&Sort3 }, 'D' => { func => \&Sort4 }, 'E' => { func => \&Sort5 }, ); sub GeneralizedFunction { my ( $flag ) = @_; # some processing if ( defined $Functions{ $flag } ) { $Functions{ $flag }{func}->(); # generalized sort } # other processing }
I warn you this is untested, but it's very similar to code I use with great frequency.