Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine


by smitz (Chaplain)
on Sep 09, 2003 at 13:30 UTC ( [id://290029]=note: print w/replies, xml ) Need Help??

in reply to

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.


Replies are listed 'Best First'.
Re: Re:
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
      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 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.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://290029]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-06-19 15:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.