PERL. Check if subroutine exists

Posted on 2007-10-11
Medium Priority
Last Modified: 2013-12-25
Looking for a way to find out if a named subroutine exists.

If I use the following string to invoke test.cgi:


and within test.cgi I have the code:

some cmd line parsing here, then
my $act=$FORM{act};
sub response [
print "OK";

I want to catch a subroutine that does not exist before the default error handler gets it. Like if someone types:  test.cgi?act=resp0nSe I want to stop the script gracefully since this routine is not valid.

Question by:Bob-Villa
LVL 48

Accepted Solution

Tintin earned 1000 total points
ID: 20062929

print "$act does not exist\n" unless defined &$act;
LVL 85

Expert Comment

ID: 20065204
Do you really want to let the user do things like

it may be safer to do something like
response => \&response,
resp0nSe => \&resp0nSe,
&{$act{$act}||sub{print "$act does not exist\n"}};

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month17 days, 5 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question