gnewitall
Programmer
- Sep 15, 2005
- 6
How do I call a subroutine named in a string?
Instead of:
sub test($$) {
my $lookfor = shift;
my $string = shift;
print "\n$lookfor ";
if($string =~ m/($lookfor)/) { print " is in ";
} else {
print " is NOT in "; } print "$string."; if(defined($1)) { print " <$1>"; } print "\n";
}
test("st.v.", "steve was here");
-------------------------------------------
I need something like:
$string = "test"; # subroutine name defined in string
Then I need to call the test subroutine using $string instead of calling it directly as shown above. How is this done?
Thanks in advance.
Instead of:
sub test($$) {
my $lookfor = shift;
my $string = shift;
print "\n$lookfor ";
if($string =~ m/($lookfor)/) { print " is in ";
} else {
print " is NOT in "; } print "$string."; if(defined($1)) { print " <$1>"; } print "\n";
}
test("st.v.", "steve was here");
-------------------------------------------
I need something like:
$string = "test"; # subroutine name defined in string
Then I need to call the test subroutine using $string instead of calling it directly as shown above. How is this done?
Thanks in advance.