fork(5) download
  1. sub foo {}
  2. sub bar {}
  3. sub baz {}
  4.  
  5. sub pick_at_random {
  6.  
  7. my %table = @_;
  8. return ( values %table )[ rand( keys %table ) ];
  9. }
  10.  
  11. my %lookup = ( A => \&foo,
  12. B => \&bar,
  13. C => \&baz );
  14.  
  15. my $selected = pick_at_random( %lookup );
  16.  
  17. print $selected == \&foo ? "Got 'foo'" :
  18. $selected == \&bar ? "Got 'bar'" :
  19. $selected == \&baz ? "Got 'baz'" :
  20. "Got nadda" ;
Success #stdin #stdout 0s 4596KB
stdin
Standard input is empty
stdout
Got 'foo'