in reply to Avoiding user-input in sub calls.
The first method is the obvious method, it is not necessarily a bad method at all.if (condition1) { code_for_condition1($data) } elsif (condition2) { code_for_condition2($data) } else { default_condition($data) }
The second method using a hash table requires more Perl knowledge. It has a slightly more complicated syntax structure, and a hash table overhead. It is nevertheless a good method.%despatcher = ( ident_1 => \*code_for_condition1, ident_2 => \*code_for_condition2, ... }; &$despatcher{$identifier}($data); sub code_for_condition1 { ... } sub code_for_condition2 { ... }
|
|---|