in reply to http://www.url.com/cgi-bin/file.pl?node=how

Hi,
Your first code snippet contains
my $node; if ($node eq...
Is this a typo? $node will always eq undef in this case. Did you mean
my $node = param('node')
You could do it something like this: (untested code):
#!/usr/bin/perl use CGI; my $node = param('node'); my %lookup_table = (how => 'how_sub', foo => 'foo_sub'); if ($lookup_table{$node} ne '') { &{$lookup_table{$node}}; } else { print "Unknown sub called\n"; } sub how_sub {} sub foo_sub {}
The %lookup_table and if routine makes sure users cant choose any old sub to run,
just the ones you define in the lookup_table.

Smitz

Replies are listed 'Best First'.
Re: Re: http://www.url.com/cgi-bin/file.pl?node=how
by surrealistfashion (Acolyte) on Sep 10, 2003 at 03:08 UTC
    I was under the impression that having it $node undef was ok, if I declared it in the Url.
    I will try the lookup_table when I am off work tonight.
    With your code does the param('node') come from the Url?
    I have more reading to do :D
    Thanks
      Hi surrealistfashion,

      Yes you do have some more reading to do :-) Check out the following:


      Although you have the sub name in your URI, and the CGI.pm module has access to it, you have not 'imported' it into your program.
      Just by declaring it with my doesn't automatically give it the value you woul like. This isn't PHP you know ;-)
      Also, I ran the code I posted, it should work fine.

      Smitz