Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call a subroutine from a string?

Status
Not open for further replies.

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.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top