dideod.yang has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; ## examples of sub_function. sub test { print "test\n" } sub test2 {print "test2\n" } sub test3 {print "test3\n" } ## pair up variables with sub_function. my $test = \&test; my $test2 = \&test2; my $test3 = \&test3; my @array = qw/ test test2 test3 /; ## I want to call sub_function each $array. but it is not working.. foreach my $array (@array) { &$$array } ## I want to print test test2 test3 like below examples. ## But below examples is not that good way. please help me :) foreach my $array (@array) { if($array eq "test" ) { $test } if($array eq "test2") { $test2} if($array eq "test3") { $test3} }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: call sub_function easily
by Athanasius (Archbishop) on Mar 03, 2019 at 09:33 UTC | |
by kevbot (Vicar) on Mar 03, 2019 at 23:47 UTC | |
|
Re: call sub_function easily
by tybalt89 (Monsignor) on Mar 03, 2019 at 09:34 UTC | |
|
Re: call sub_function easily (updated)
by haukex (Archbishop) on Mar 03, 2019 at 08:42 UTC | |
|
Re: call sub_function easily
by tybalt89 (Monsignor) on Mar 03, 2019 at 17:31 UTC | |
|
Re: call sub_function easily
by karlgoethebier (Abbot) on Mar 03, 2019 at 10:08 UTC |