I'm messing around with trying to link to different sections in a script, so that I can click on a link (ie. script.cgi?abc, and &abc; will run). It works, but with some *issues*.
#!perl -w
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser); #errors will show in browser
my $q = new CGI;
print qq!
<a href="script.cgi?one">one</a>
<br>
<a href="script.cgi?two">two</a>
<br>
<a href="script.cgi?three">three</a>
!;
if($q->param){
my $sub = $ENV{'QUERY_STRING'};
if(defined &$sub){
print "<BR><BR>";
&$sub;
}else{
print "<BR><BR>";
&error;
}
}
sub one {
print "sub... one";
}
sub two {
print "sub... two";
}
sub three {
print "sub... three";
}
sub error {
print "ERROR\!\!";
}
If you comment out 'use strict;', this will work with no problems... but with strict on, it won't allow me to use the call &$sub;. Is there an easy way to get around that problem? Also, is there an easier way of doing what I'm trying to do here? (in that above code, I know that I can take off if($q->param) { }, however I'll be needing it later, so I just left it =P
Any help would be appreciated.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|