austin43 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I am trying to create a simple script that will step through existing subroutines in a list when a certain condition is met for each.
$input = <>; if ($input = 0) { &routine0; } elsif ($input = 1) { &routine1; } else { exit; }
That is an example of how it currently reads, but I want something a bit easier to scale, as there will be many subroutines to call. How would I have an array contain subroutines and step forward or backward in that array when a certain condition is met? Thanks in advance.

Replies are listed 'Best First'.
Re: Step through an array containing subroutines
by ikegami (Patriarch) on Feb 15, 2011 at 18:06 UTC
    my @routines = ( \&routine0, \&routine1, ); $routines[$input]->();
      Thanks! Here's what the finished code looks like.
      my @routines = ( \&routine0, \&routine1, ); $routines[$input]->($input = <>); sub routine0 { print "0"; } sub routine1 { print "1"; }