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.