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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|