http://www.perlmonks.org?node_id=60714


in reply to Improving the efficiency of this piece of code

I would probably use a hash for this, with the values as subroutine references. Here's a simple example:
#!/usr/bin/perl -wT use CGI qw(:all); use CGI::Carp qw(fatalsToBrowser); my %dispatch = ( '' => \&index, page2 => \&page2, page3 => \&page3, default => \&index, ); my $page = param('page'); my $subref = $dispatch{$page} || $dispatch{default}; $subref->();