All of which prints:use strict; use warnings; sub a1 { print("a1\n"); } sub a2 { print("a2\n"); } my @procs = (\&a1, \&a2); foreach (@procs) { &$_; } # or for a more idiomatic approach # enter anonymous subs directly into the array: my @procs2 = (sub { print("this\n") }, sub { print("that\n") } ); foreach (@procs2) { $_->(); # alternate form to call subroutine ref }
------------------------------------------------------------
"Perl is a mess
and that's good because the
problem space is also a mess." - Larry Wall
In reply to Re: How can I call subroutines in an array
by dvergin
in thread How can I call subroutines in an array
by ozgurp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |