#!/usr/bin/perl -w package PLCFuncs; sub calcTot { "The total is 10 PLCs" }; package PPDFuncs; sub calcTot { "The total is 42 PPDs" }; package Generic_Funcs; use strict; use Carp qw(croak); =head2 C Returns the calculated total. The kind is either C or C. =cut use vars qw(%calcTotals); %calcTotals = ( PLC => \&PLCFuncs::calcTot, PPD => \&PPDFuncs::calcTot, ); sub calculate_totals { my ($kind) = @_; croak "Unknown kind '$kind'" unless exists $calcTotals{ $kind }; my $calcTot = $calcTotals{$kind}; $calcTot->(); }; package main; use strict; for my $kind (qw(PPD PLC)) { print "Totals for $kind\n"; print Generic_Funcs::calculate_totals($kind), "\n" };