in reply to How to call sub defined in a variable?
#!/usr/bin/perl use strict; use warnings; package MySubs; sub test { print "something"; } sub another_test { print "something else"; } sub third_test { print "another unimaginative statement"; } 1; package main; my @ary = qw( test another_test third_test ); my $sub_i_want_to_call = $ary[rand(@ary)]; my $subref = MySubs->can($sub_i_want_to_call); &$subref() if $subref;
|
|---|