From BluWiki
Code, fnRefs.pl
#!/usr/local/bin/perl -w
use strict;
my %fnRef;
$fnRef{'Chicago'} = \&fnChi;
$fnRef{'Cincinnati'} = \&fnCin;
$fnRef{'Houston'} = \&fnHou;
$fnRef{'Pittsburgh'} = \&fnPit;
$fnRef{'St. Louis'} = \&fnStL;
my $city = $ARGV[0];
my $msg = $ARGV[1];
$fnRef{$city}->($msg) if (defined($fnRef{$city}));
print "huh?\n" unless(defined($fnRef{$city}));
# ----------------------------------------------- fnChi
sub fnChi {
my $msg = shift;
print "Cubs. $msg\n";
}
# ----------------------------------------------- fnCin
sub fnCin {
my $msg = shift;
print "Reds. $msg\n";
}
# ----------------------------------------------- fnHou
sub fnHou {
my $msg = shift;
print "Astros. $msg\n";
}
# ----------------------------------------------- fnPit
sub fnPit {
my $msg = shift;
print "Pirates. $msg\n";
}
# ----------------------------------------------- fnStL
sub fnStL {
my $msg = shift;
print "Cardinals. $msg\n";
}
Output
./fnRefs.pl Cincinnati "Kilroy was here"
Reds. Kilroy was here
Perl Programming, Cookbook