use strict; use CGI; use Template; $|++; # Dispatch table is a hash where # every value is a sub-reference # When the user doesn't provide # a run-mode, then list() is # triggered (default case, see # the last line my %dispatch_table = ( list => \&list, item => \&item, fetch_image => \&fetch_image, '' => \&list, ); my $query = new CGI; print $query->header; print $query->start_html( -title => 'A small example...' ); # Now we read the param mode from # the query. The string is used to # fetch the hash table. We got a # reference to a function, so we # can call it... my $mode = $query->param('mode'); &{ $dispatch_table{$mode}}; print $query->end_html; sub list { print "