Light weight OO is a neat solution for this. Consider:
use strict; use warnings; my $obj = bless {}; my $verb = 'AddAccount'; for my $os (qw(SUN HP XP)) { my $sub = $obj->can ("${os}AddAccount"); if (! $sub) { print "Don't know how to $verb for $os\n"; } else { $sub->($obj); } } sub LINUXAddAccount { my ($self) = @_; print "Linux goes moo\n"; } sub AIXAddAccount { my ($self) = @_; print "AIX goes moo\n"; } sub HPAddAccount { my ($self) = @_; print "HP goes moo\n"; } sub SUNAddAccount { my ($self) = @_; print "SUN goes moo\n"; }
Prints:
SUN goes moo HP goes moo Don't know how to AddAccount for XP
Note that all you need do to support XPAddAccount is add the sub - no tables to update or any other code changes required.
In reply to Re: Call Subroutine with Variable
by GrandFather
in thread Call Subroutine with Variable
by walkingthecow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |