# In perl:
sub configpc 
{
   my ($cpu,$ghz,$megs,$gigs) = @_;
   my ($printinfo,$upgrade,$getghz,$fasterthan);  # methods
   $printinfo = sub
    {
      print "$ghz ghz $cpu cpu with $megs megs of RAM and a $gigs gig hard drive";
    };
   $upgrade = sub { $megs *= 2; $ghz += $ghz/2; };
   $getghz = sub { $ghz };
   $fasterthan = sub 
    {
        my $otherpc = $_[0];
	$ghz > $otherpc->("getghz");
    };
   
   # interface (or dispatch) function:
   sub {  my $method = $_[0];
          $print->() if ($method eq "print");	
          $upgrade->() if ($method eq "upgrade");
	  $getghz->() if ($method eq "getghz");
	  $fasterthan if ($method eq "fasterthan");  # function returned here
       }  
} # configpc

my $oldpc = configpc("athlon xp1800+",1.5,256,40);
my $newpc = configpc("pentium4 775 lga",3.2,768,200);
$oldpc->("upgrade");  # the ""'s can actually be left out
print "the new pc is faster"  unless !($newpc->("fasterthan")->($oldpc));
