SPUG: Hashes and subroutines

Simon Wilcox essuu at ourshack.com
Tue Jan 6 00:13:23 PST 2009

Christopher Howard wrote:
> I've got this situation where I execute a certain subroutine based on 
> the value of a variable, like so:
> if($var eq 'play') { sub1() }
> elsif($var eq 'that') { sub2() }
> elsif($var eq 'funky') { sub3() }
> elsif($var eq 'music') { sub4() }
> ...
> Is there some way to do this with a hash instead?

As others have said, dispatch tables are what you're looking for. I've 
always thought this article to be a really good introduction:



More information about the spug-list mailing list