in reply to Interesting CGI Problem...

Hi Spidy,

After you got it to work, consider changing your 'if' and 'elsif' to:

my $query = get_param('node') || 'default'; my %nodes = ( default => \&default, news => \&news, records => \&records, quests => \&quests, help => \&help, _err => \&invalid ); eval { $nodes{ exists $nodes{$query} ? $query : '_err' }(); };

Replies are listed 'Best First'.
Re^2: Interesting CGI Problem...
by edan (Curate) on Aug 29, 2004 at 06:34 UTC

    You certainly have a good point about using a hash as a dispatch table, but I utterly fail to understand why you would need to use eval. How about:

    my $dispatch = $nodes{$query} || $nodes{_err}; $dispatch->();

    Or if you really like to put everything in one line:

    ( $nodes{$query} || $nodes{_err} )->();
    --
    edan

      Hi edan,

      Thanks for pointing out. I missed out the catch error code below:

      if ($@) { dienice(); }
Re^2: Interesting CGI Problem...
by dragonchild (Archbishop) on Aug 30, 2004 at 12:17 UTC
    Why suggest this when you could just use CGI::Application which does all of this, and more?

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      Hi dragonchild,

      Spidy appears to be new to Perl CGI and is trying to get basic things to work. He's using a chain of 'if' and 'elsif' which can be improved with the hash director thingy without too much sweat.

      I've heard of CGI::Application but have not used it before.