in reply to Dynamic functions

The question is not entirely obvious to me (see I know what I mean. Why don't you?), but perhaps you would like to use a dispatch table, which is implemented with a hash of subroutine references:

#!/usr/bin/perl -w use strict; my %dispatch = ( f11 => \&function11, f12 => \&function12, f21 => \&function21, f22 => \&function22, ); sub function11 { return "Function 1-1\n"; } sub function12 { return "Function 1-2\n"; } sub function21 { return "Function 2-1\n"; } sub function22 { return "Function 2-2\n"; } for my $i (1..2) { for my $j (1..2) { print $dispatch{"f$i$j"}->(); } }

See perlref for more information on sub refs.

Replies are listed 'Best First'.
Re^2: Dynamic functions
by himik (Acolyte) on Sep 11, 2011 at 12:23 UTC
    Thank you that is what i search for.