I have 5 Perl files that are verification scripts for 5 different states of my environment.
Each of them has at least a couple of subroutines.
Till now, the number of states was limited to 5 and these worked fine. But now, I have like 20 more states of the environment and hence 20 more Perl scripts according to the current design.
I want to move all the five scripts to just one script which takes the state as an argument and have 5 different subroutines for 5 different states.
This way, when I need to add a verify for yet another state, I will just have to define a new subroutine instead of a whole new Perl script.
The problem is that it will mean using nested subroutines (which are known to run into issues), or unrolling the subroutines themselves.
For example,
original scripts
$ cat verify1.pl
sub a1 {
...
}
sub b1 {
...
}
a1(); b1(); a1();
$ cat verify2.pl
sub a2 {
...
}
sub b2 {
...
}
sub c2 {
...
}
a2(); b2(); c2(); a2();
$
consolidated script
$ cat verify.pl
sub one {
...
}
sub two {
...
}
my ($arg) = @ARGV;
if ($arg == 1) {
one(); # should do what verify1.pl did
}
elsif ($arg == 2) {
two(); # should do what verify2.pl did
}
$
What should I do to resolve this?